Question

When I enter a query containing multiple word to my Suggester component I got separated results for each. The problem is well explained here: How to have Solr autocomplete on whole phrase when query contains multiple terms?

The only difference is, I have a suggester based on a dictionary file, not an index field. The solution explained in the above link and many others didn't work

Here is the configuration:

<searchComponent class="solr.SpellCheckComponent" name="suggest">
    <lst name="spellchecker">
        <str name="name">suggest</str>
        <str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
        <str name="lookupImpl">org.apache.solr.spelling.suggest.fst.AnalyzingInfixLookupFactory</str>
        <str name="buildOnCommit">true</str>
        <str name="suggestAnalyzerFieldType">text_suggest</str>
        <str name="sourceLocation">suggestionsFull.txt</str>
    </lst>
    <str name="queryAnalyzerFieldType">text_suggest</str>
    <!-- <queryConverter name="queryConverter" class="org.apache.solr.spelling.SuggestQueryConverter"/> -->
</searchComponent>

<requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/suggest">
    <lst name="defaults">
        <str name="spellcheck">true</str>
        <str name="spellcheck.dictionary">suggest</str>
        <str name="spellcheck.onlyMorePopular">true</str>
        <str name="spellcheck.count">5</str>
        <str name="spellcheck.collate">false</str>
    </lst>
    <arr name="components">
        <str>suggest</str>
    </arr>
</requestHandler>

schema.xml

<fieldType name="text_suggest" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.TurkishLowerCaseFilterFactory"/>
        <filter class="solr.TrimFilterFactory"/>
    </analyzer>
</fieldType>

I also use spellcheck.q parameter instead of q

http://localhost:8983/solr/collection1/suggest?spellcheck.q=bu+bir&wt=json&indent=true

What am I doing wrong?

Was it helpful?

Solution

Finally I found the solution:

Looks like even if you build the suggestion dictionary from a file but not from an index field, you have to specify an index field in the solrconfig. Thus in the schema.xml create a dummy field from the text_suggest fieldtype which we had already created:

<field name="text_suggest" type="text_suggest" indexed="false" stored="false" />

Then in the solrconfig.xml add <str name="field">text_suggest</str> line to the searchComponent:

<searchComponent class="solr.SpellCheckComponent" name="suggest">
       <lst name="spellchecker">
          <str name="name">suggest</str>
          <str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
          <str name="lookupImpl">org.apache.solr.spelling.suggest.fst.AnalyzingInfixLookupFactory</str>
          <str name="buildOnCommit">true</str>
          <str name="suggestAnalyzerFieldType">text_suggest</str>
          <str name="field">text_suggest</str>
          <str name="sourceLocation">suggestionsFull.txt</str>
       </lst>
    </searchComponent>

Restart the solr and you're done!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top