[英]Hybris : How to exclude Facet Value from the Solr Result
Hybris 5.2 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. 我正在做一些分析,以从Solr Search中排除Facet Value,以便这些产品不会出现在搜索结果中。
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. 假设我有很多彩色T恤(不知道有多少种颜色),有人告诉我不要在搜索结果中显示红色T恤 。
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 选项1:我必须在系统中获得所有T恤的颜色,然后在Solr结果中添加一个过滤器
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. 这将添加一个颜色SolrIndexedProperty的过滤器,并将解决问题。
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. 选项2:从Solr搜索结果中排除红色属性,而不是对所有颜色应用过滤器。
Solr Query would be like this .. Solr Query就像这样..
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. 这将从结果中排除红色T恤。 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 ? 任何人都可以知道如何在Hybris中使用service / method / searchQuery实现此查询(q= *:* AND -color_string:red)
?
So After some hit and try, I got the Solution. 所以经过一番打击和尝试后,我得到了解决方案。
In searchQuery, we can add Raw Query as well. 在searchQuery中,我们也可以添加Raw Query。 So I have set the query in addRawQuery method. 所以我在addRawQuery方法中设置了查询。
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!! 这使它工作!!
SolrIndexedProperty具有属性,includeInResponse如果将其设置为false,则不会在结果中发送。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.