By default Oracle Endeca Navigation query result would contain all the stored (searchable and non searchable) properties in the index. In many cases you may not want to show all the properties in the screen. Reducing the number of properties returned from the MDEX would also increase the performance of the whole query process. In this post we will share a sample navigation query that would limit the properties in the ERec to three.
This sample program would connect to an Oracle Endeca MDEX server and make a navigation query. Query will be applied with nid zero. This client connect to Oracle Endeca MDEX installed in localhost at default port 15000.
How to create navigation query that limit the properties in the result?
1 2 3 4 5 6 7 8 |
final ENEQuery query = new ENEQuery(); final DimValIdList dimValIdList = new DimValIdList("0"); query.setNavDescriptors(dimValIdList); final FieldList fieldList = new FieldList(); fieldList.addField("product.id"); fieldList.addField("product.name"); fieldList.addField("product.price"); query.setSelection(fieldList); |
Complete sample program.
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 |
package com.ourownjava.endeca.presentation; import com.endeca.navigation.ENEConnection; import com.endeca.navigation.ENEQuery; import com.endeca.navigation.ENEQueryException; import com.endeca.navigation.HttpENEConnection; import com.endeca.navigation.Navigation; /** * How to reduce the size of the Oracle Endeca Navigation query result. * * @author ourownjava.com * */ public class NavigationQueryLimitProperties { private static final String MDEX_HOST = "localhost"; private static final Integer MDEX_PORT = 15000; public Navigation serach(final ENEQuery eneQuery) throws ENEQueryException{ return createConnection().query(eneQuery).getNavigation(); } /** * @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 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 80 81 82 83 84 85 86 87 |
package com.ourownjava.endeca.presentation; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; import com.endeca.navigation.DimValIdList; import com.endeca.navigation.ENEQuery; import com.endeca.navigation.ENEQueryException; import com.endeca.navigation.ERec; import com.endeca.navigation.FieldList; import com.endeca.navigation.Navigation; /** * * This code is tested against the Oracle Endeca Discover Electronic reference application. * * @author ourownjava.com * */ public class NavigationQueryLimitPropertiesBehavior { private NavigationQueryLimitProperties navigationQueryLimitProperties; @Before public void setUp(){ this.navigationQueryLimitProperties = new NavigationQueryLimitProperties(); } @Test public void shouldReturnOnlyThreeProperties() throws ENEQueryException{ final Navigation navigation = navigationQueryLimitProperties.serach(createNavigationQuery("0", true)); assertEquals(10, navigation.getERecs().size()); for(Object element : navigation.getERecs()){ final ERec eRec = (ERec)element; assertEquals(3, eRec.getProperties().size()); } } @Test public void shouldReturnAllProperties() throws ENEQueryException{ final Navigation navigation = navigationQueryLimitProperties.serach(createNavigationQuery("0", false)); assertEquals(10, navigation.getERecs().size()); for(Object element : navigation.getERecs()){ final ERec eRec = (ERec)element; assertTrue(eRec.getProperties().size() > 10); } } /** * List the ERec properties to only three items. * * @return */ private FieldList createFieldListForSearchResult(){ final FieldList fieldList = new FieldList(); fieldList.addField("product.id"); fieldList.addField("product.name"); fieldList.addField("product.price"); return fieldList; } /** * This method shall create an Oracle Endeca Navigation query. * * This query would ask only first 10 records and 3 properties. * * @param nValue * @return */ private ENEQuery createNavigationQuery(final String nValue, boolean limitRecords) { final ENEQuery query = new ENEQuery(); final DimValIdList dimValIdList = new DimValIdList(nValue); query.setNavDescriptors(dimValIdList); //ask only first 10 records query.setNavNumERecs(10); //ask only three properties if(limitRecords){ query.setSelection(createFieldListForSearchResult()); } return query; } } |
You forget to put : after http for this anchor:”Please take a look at this post if you have not already installed the Oracle Endeca” – https://ourownjava.com/endeca/
Thank You. I have fixed it.