Solr filter query for suggester

4.7k views Asked by At

I'm using the Solr Suggester Component, and was wondering, if the results can be filtered by the fq parameter. I have a query like this:

http://localhost:8982/solr/core1/suggest?q=shirts&fq=category_id%3A321&wt=json&indent=true&spellcheck=true&spellcheck.build=true

Here, I try to get some suggestions for q=shirts. I want to filter this by fq=category_id:321, so that I don't get suggestions from other categories. Because category with the category_id:321 doesn't have any products related to shirts, it shouldn't return any suggestions. But it does. And when trying to search for that suggestion, it doesn't find anything, because the "original" search is filtered with the fq=... parameters.

I found something with collate here http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.collate. It collates my results, but also returns suggestions for shirts.

So my question is, is the Suggester (or basically the SpellCheckerComponent) aware of the fq parameter, and how can I use this parameter to filter the suggestions (or in a later stage, the spelling corrections).

EDIT

I found out, that the "normal" spellcheck component (e.g. with the class solr.IndexBasedSpellChecker for example), does indeed take the fq parameter into account. I can set

   <str name="spellcheck.collate">true</str>
   <str name="spellcheck.collateExtendedResults">false</str>

and a suggestion for shitr is not returned when filtering by a certain category id, where the keyword shirt is not present.

I'm wondering, why this doesn't work with the suggest component. Any ideas?

1

There are 1 answers

1
Arun On

I do not think so, you need to look at this a bit differently to understand why. As you may already know, the SpellChecker operates based on dictionary built from the field you specified in the config.

default text solr.DirectSolrSpellChecker ...

And the copy fields that should makeup your dictionary during indexing fill the "text" field hence the dictionary. Example :

At this point spell checker does not know where the suggestion came from.

So with collation you can do little better, did you try &spellcheck=true&spellcheck.extendedResults=true&spellcheck.collate=true ? This will make sure suggestion has some results .

The spellcheck.extendedResults ,Provide additional information about the suggestion, such as the frequency (hits) in the index, which may help you in your logic.