cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Building SOLR filter query with the OR operator in SearchFilterQueryData

Former Member
0 Kudos
6,590

Hi Experts,

During the search in the CategoryPageController I am trying to modify the SOLR query and add some filter parameters (about 4 filter params) and example like this:

 final SearchFilterQueryData searchNameFilterQuery = new SearchFilterQueryData();
 searchNameFilterQuery.setKey("name");
 searchNameFilterQuery.setValues(new HashSet<> 
   (Collections.singletonList(queryData.get("name"))));
 searchNameFilterQuery.setOperator(FilterQueryOperator.OR);

and add it to the this.searchQueryData.setFilterQueries list.

Now in the query being formed,

yq=:&q={!boost}(%2B{!lucene+v%3D$yq})&fq=allCategories_string_mv:1 &fq=gskProductAvailability_string_mv:ACTIVE&fq=code_string:ACLOV &fq=name_usecscontext_en_us_text:ACLOV&fq=productIdentifier_text_mv:ACLOV

So currently the query is adding one fq parameter for every attribute searched for,however I want an OR condition here, something like fq=(gskProductAvailability_string_mv:ACTIVE OR code_string:ACLOV OR name_usecscontext_en_us_text:ACLOV OR productIdentifier_text_mv:ACLOV

How can I enable this through the SearchFilterQueryData or similar? Anyone has faced anything similar?

Regards, Viral

Accepted Solutions (0)

Answers (3)

Answers (3)

a_e_dubey
Active Participant

Hello , You can do this using SolrQuery object instead of Hybris out of box classes. Solr provide this functionality so you have to set these condition directly to SolrQuery class. I can provide you way.

Assuming you are using 6.x

  • Step 1 - Extend DefaultFacetSearchStrategy/AbstractFacetSearchStrategy and override

  • Step 2 - Override public SearchResult search().

  • Step 3 - Here object of SolrQuery is available.

  • Step 4 - solrQuery.addFilterQuery("gskProductAvailability_string_mv:ACTIVE OR code_string:ACLOV OR name_usecscontext_en_us_text:ACLOV OR productIdentifier_text_mv:ACLOV")

This will work. Let me know if help you.

Former Member
0 Kudos

Hi Abhishek,

Thank you for the reply. So since these filter query parameters are coming dynamically from the site, how do I pass these from the controller to the overridden DefaultFacetSearchStrategy?

Regards, Viral

a_e_dubey
Active Participant
0 Kudos

There are multiple way to this,

  • Complex is to create you new bean and add this to existing flow like in in DefaultSolrSearchFacade, DefaultSolrSearchService, *Search*Query*Converter, Populator,SearchQuery.

  • You can populate as SearchFilterQueryData and apply if else in FacetSearchStrategy and remove form SearchQuery what is added by you in SearchFilterQueryData .

  • Simplest way to do this but use with carefully , set all list in session and get it here.

0 Kudos

Hi Viral, you can do this by extending existing SearchFilterPopulator. There you will get SearchQuery object to add filter query and set operator as well.

Former Member
0 Kudos

Hi Namrata,

Thanks for the reply, I have achieved this by implementing the FacetSearchListener and manipulating the SearchQuery by using Raw Query rather than using FilterQuery or populating it.

Regards, Viral

vinay_malempati
Active Participant
0 Kudos

Hi Viral,

You can do this the other way round by using the free text search having category filter applied on top

Former Member
0 Kudos

Thanks for the answer Vinay, but why can't we use the categorySearch here ?

Former Member
0 Kudos

Vinay, tried this, however it does not seem to work. Thanks