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); } } |
Pingback: How to make keyword search in Endeca using presentation API? | Clean Java
Thanks a lot !! It was hard to find sample(working) code for endeca .. You made my day
… One question, How do we query against a property type ( For E.g Product_Name=”XYZ” )?
Thanks Sathish. Check out https://ourownjava.com/endeca/endeca-presentation-api-navigation-query-multiple-ids to see the answer.
Hi,
Hi,
I am new to Endeca, I want to write a endeca query in java for searching products based on product ids(Its Multiple Ids at one shot) in java, I am able to write it for a single id
final ENEQuery query = new ENEQuery();
final DimValIdList dimValIdList = new DimValIdList(“0″);
query.setNavDescriptors(dimValIdList);
final ERecSearchList searches = new ERecSearchList();
final ERecSearch eRecSearch = new ERecSearch(“P_product_code”,”180479110421272″);
searches.add(eRecSearch);
query.setNavERecSearches(searches);
In this case i am getting the out put, but when i want to search the product based on two Ids i,e 180479110421272 and 260036825042 at a time , then i am not getting how to build the query, Kindly help me out .
when i write for 2 productIds then its not showing any records.(I am not sure wheather its right or worng)
final ERecSearchList searches = new ERecSearchList();
final ENEQuery query = new ENEQuery();
final DimValIdList dimValIdList = new DimValIdList(“0″);
query.setNavDescriptors(dimValIdList);
final ERecSearchList searches = new ERecSearchList();
final ERecSearch eRecSearch = new ERecSearch();
searches.add(eRecSearch);
searches.add( new ERecSearch(“P_product_code”,”180479110421272″));
searches.add( new ERecSearch(“P_product_code”,”260036825042″));
query.setNavERecSearches(searches);
hi Madhu, check out https://ourownjava.com/endeca/endeca-presentation-api-navigation-query-multiple-ids/ to see the answer.
I am new to the endeca.I need to write query in java to search the product based on product code(one of the properties) in java.
I have written below code for it
final ERecSearchList searches = new ERecSearchList();
final ENEQuery query = new ENEQuery();
final DimValIdList dimValIdList = new DimValIdList(“0?);
final ERecSearch eRecSearch = new ERecSearch(“P_product_code”,”1234235″);;
searches.add(eRecSearch);
query.setNavERecSearches(searches);
For the above code I am able to get output which contain attributes of DERIVED PROPERTIES and few attributes of REPRESENTATIVE REC PROPERTIES(able to get all the attributes of DERIVED PROPERTIES and few attributes of REPRESENTATIVE REC PROPERTIES).
But I need to write query in java to get the record level details all the attributes .
hi Vijaya, I didn’t understand your question clearly. Ideally speaking ERec.getProperties() would return a key value pair of all the indexed and stored attributes of record. Check if those attributes are listed in the jsp reference application.
Hi,
On search of product code below attributes are displayed in the jsp reference page. I am also able to query these attributes.
2herhew895749835 (1 Record)
PROPERTIES:
MIN_SALE: 10
MAX_SALE: 4
MIN_LIST: 6
MAX_LIST: 6
REC PROPERTIES:
Store: N
online: ahgsja
clearance: s
color: G
color: Pewter
comp_size: One Size
INVENTORY_AVAIL: 16
inventory_level: 16
isPattern: F
listPrice: 60.000000
After the search result obtained .On further click on the record(2herhew895749835) in jsp reference page below attributes are obtained.
Now I need to write the query in java to obtain all the attribute present below at record level.
2herhew895749835 (1 Record)
PROPERTIES:
MIN_SALE: 10
MAX_SALE: 4
MIN_LIST: 6
MAX_LIST: 6
REC PROPERTIES:
Store: N
online:
brand Ahgsja
sdfdsfff
clearance: s
color: G
color: Pewter
comp_size: One Size
INVENTORY_AVAIL: 16
inventory_level: 16
isPattern: F
listPrice: 60
reserved: 0
saleprice: 4
sku_code: 048
sku_upc: 126329
skus_sale_price: 44
vendor_number: 2tyut
vendor_style: vnjvnjvjgjg
wedding_skus_sale_price: T876868
RECORDSPEC: Y6326598432 jdhfiu
ROLLUPKEY: 398257 nfeor84u09tc8
All the record level properties can be extracted from ERec, You may not have to do anything with Query. You have to look at ERec.getProperties(), This method returns all the record properties, its a key value of pair. Key is what you see in the jsp application before “:” and value is what is shown after the “:”. (sku_code: 048) Check out this code segment.
final ERec eRec = (ERec) result;
for (Object key : eRec.getProperties().keySet()) {
System,out.println(key);
System.out.println(eRec.getProperties().get(key));
}
}
Hey team u r rocking …