Sample client which connect to an Oracle Endeca MDEX server and make a navigation search. Query will be applied with nvalue zero or root. This program assume that the MDEX installed in localhost and running on port 15000.
Sample code to create a navigation query
1 2 3 4 |
final ENEQuery query = new ENEQuery(); final DimValIdList dimValIdList = new DimValIdList(<<nvalue>>); query.setNavDescriptors(dimValIdList); query.setNavNumERecs(<<number_of_records>>); |
Class DimValIdList has three constructors.
- DimValIdList()
- DimValIdList(DimValList values)
- DimValIdList(String ids)
DimValList is a java.utl.List implementation, If you have multiple ‘nids’ then you may use the second constructor.
setNavNumERecs(int number) method set an integer specifying the maximum number of records to return for the navigation query.
Complete Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
package com.ourownjava.search.endeca; import com.endeca.navigation.DimValIdList; import com.endeca.navigation.ENEConnection; import com.endeca.navigation.ENEQuery; import com.endeca.navigation.ENEQueryException; import com.endeca.navigation.ENEQueryResults; import com.endeca.navigation.ERec; import com.endeca.navigation.HttpENEConnection; /** * * @author ourownjava.com * */ public class NavigationSearchClient { private static final String MDEX_HOST = "localhost"; private static final Integer MDEX_PORT = 15000; /** * @param args * @throws ENEQueryException */ public static void main(final String[] args) throws ENEQueryException { final ENEQueryResults results = createConnection().query(createNavigationQuery("0")); final StringBuilder builder = new StringBuilder(); builder.append("Found "); builder.append(results.getNavigation().getERecs().size()); builder.append(" results.\n"); for (Object result : results.getNavigation().getERecs()) { final ERec eRec = (ERec) result; for (Object key : eRec.getProperties().keySet()) { builder.append(key); builder.append(" >> "); builder.append(eRec.getProperties().get(key)); } } System.out.println(builder.toString()); } private static ENEQuery createNavigationQuery(final String nValue) { final ENEQuery query = new ENEQuery(); final DimValIdList dimValIdList = new DimValIdList(nValue); query.setNavDescriptors(dimValIdList); query.setNavNumERecs(100); return query; } /** * @return */ private static ENEConnection createConnection() { return new HttpENEConnection(MDEX_HOST, MDEX_PORT); } } |
Pingback: How to make a navigation query in Endeca using presentation API? | Clean Java