Solr to remove faceted field when it doesn't h

2019-06-02 17:12发布

问题:

Working with Solr for ASP.net project using Solrnet library.

While querying with Faceted field set to true for several fields, it returns blank faceted fields in the results as well. Is there any way using which we can instruct Solr to remove those faceted fields which does not have any result into it.

So the final results doesn't include any facet field with no data. I'm not referring to min.count parameter, this works fine. But I'm referring to the facet field which stays there even if there is no data inside it.

Please comment if you didn't get my point. Thank you in advance for helping me.

回答1:

Set facet.mincount to 1.
This will ensure facets with at least one record will be returned. By default the value is 0.

Edit :- Sorry didn't get the facet part here. The Facets are always returned if even no matches in it. So the handling needs to be on the client side.



回答2:

If you want to remove facets having count = 0 then you need to Optimize your Core. That is one of the way i found. I tested it on SOLR version 6.3.X

To optimize the Core, go to SOLR Admin page and select core you want to Optimize. or Use CURL.

The CURL will look like this -

curl http://<host_name>:8983/solr/<core_name>/update -F stream.body=' <optimize />'

Hope this helps!