Sample client which connect to an Oracle Endeca MDEX server and make keyword search. Query will be applied with nid zero and the search term will be searched against all searchable keys in the index. This client connect to MDEX installed in localhost at default port 15000.
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 61 62 63 64 65 66 67 68 |
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.ERecSearch; import com.endeca.navigation.ERecSearchList; import com.endeca.navigation.HttpENEConnection; /** * @author ourownjava.com * * Example program to do keyword search using Endeca presentation API. * */ public class KeywordSearchClient { 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( createKeywordQuery("shirt")); 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()); } @SuppressWarnings("unchecked") private static ENEQuery createKeywordQuery(final String searchTerm) { final ENEQuery query = new ENEQuery(); final DimValIdList dimValIdList = new DimValIdList("0"); query.setNavDescriptors(dimValIdList); final ERecSearchList searches = new ERecSearchList(); final ERecSearch eRecSearch = new ERecSearch("All", searchTerm); searches.add(eRecSearch); query.setNavERecSearches(searches); return query; } /** * @return */ private static ENEConnection createConnection() { return new HttpENEConnection(MDEX_HOST, MDEX_PORT); } } |