3
votes

Hybris 5.2

I was doing some analysis to exclude Facet Value from the Solr Search so that those products will not come in the search result.

Suppose I have lots of Color T-Shirts (Don't know how many colors) and someone told me to not show Red color T-Shirts in the search result.

There are two options which I can think

Option 1 : I have to get all the T-Shirt's colors available in the System then add a Filter in Solr Result

For Example

            List<String> colorList = getAllColorsExceptRed(); //Get all colors except red
            for(String color : colorList) {
                  searchQuery.addFacetValue("color", color);
            }

This will add a filter of color SolrIndexedProperty and will solve the problem.

But I am not curious to pickup this approach.

Option 2 : Exclude Red Color property from Solr Search result rather than applying filter on all the colors.

Solr Query would be like this ..

            q= *:* AND -color_string:red
            //in case of multiple color exclude
            q= *:* AND -color_string: (red white)

This will exclude red T-Shirt from the result. But I am not able to find which Service or Method I should choose to make a query like this.

Can anybody know how to achieve this Query (q= *:* AND -color_string:red) with service/method/searchQuery in Hybris ?

2

2 Answers

2
votes

So After some hit and try, I got the Solution.

In searchQuery, we can add Raw Query as well. So I have set the query in addRawQuery method.

final String colors = "red white"; // List we can get from property file as well
searchQuery.addRawQuery("-color_string:(" + colors + ")",Operator.AND);

This makes it work!!

0
votes

SolrIndexedProperty has attribute, includeInResponse if you set it as false, it will not be sent in result.