Sample client which connect to an Endeca MDEX server and make keyword search. Query will be applied with nid zero and the search term will be searched against “product.id” searchable key in the index. This client connect to Endeca MDEX installed in localhost at default port 15000. In this example we search multiple product ids in one query.
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 69 70 71 72 73 74 75 76 77 78 79 |
package com.ourownjava.endeca.presentation; import java.util.HashSet; import java.util.Set; 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; /** * Endeca presentation API to connect to MDEX and do a keyword search. * @author ourownjava.com * */ 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 Set<String> productKeys = new HashSet<String>(); productKeys.add("107400"); productKeys.add("4150294"); final ENEQueryResults results = createConnection().query(createKeywordQuery(productKeys)); 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)); } builder.append("\n"); } System.out.println(builder.toString()); } @SuppressWarnings("unchecked") private static ENEQuery createKeywordQuery(final Set<String> productIds) { final ENEQuery query = new ENEQuery(); final DimValIdList dimValIdList = new DimValIdList("0"); query.setNavDescriptors(dimValIdList); final ERecSearchList searches = new ERecSearchList(); final StringBuilder builder = new StringBuilder(); for(final String productId : productIds){ builder.append(productId); builder.append(" "); } final ERecSearch eRecSearch = new ERecSearch("product.id", builder.toString().trim(), SearchMode.ANY.getMode()); searches.add(eRecSearch); query.setNavERecSearches(searches); return query; } /** * @return */ private static ENEConnection createConnection() { return new HttpENEConnection(MDEX_HOST, MDEX_PORT); } } |
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 |
package com.ourownjava.endeca.presentation; /** * * @author ourownjava.com * */ public enum SearchMode { ALL("mode matchall"), ANY("mode matchany"), PARTIAL("mode matchpartial"), ALLPARTIAL("mode matchallpartial"); private String searchMode; /** * @return mode */ public String getMode() { return searchMode; } private SearchMode(final String searchMode) { this.searchMode = searchMode; } } |
nice Work!!!
Thanks Ravi.
Can anyone help me to find jars related to this?
hi Wilson, you should be able to find the navigation api jar inside the endeca installation.
Really nice. Do you know how I can query for certain properties containing a String? For example I have 2 properties defined as String, and I want all the records that contains the input string inside that properties.
And if when need to search on different properties in OR? I’ve noticed that adding ERecSearch to the list, all the properties that I put is in AND.