Solr suggest exact match

1.2k views Asked by At

I am trying to make solr return exact match on suggestion, ex:

  • spellcheck.q=tota does return total in results but
  • spellcheck.q=total does not return total in results.

I am using this field for suggestions:

<fieldType name="textSpellShingle" class="solr.TextField" positionIncrementGap="100">
  <analyzer>
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.ShingleFilterFactory" maxShingleSize="3" outputUnigrams="true"/>
    <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
  </analyzer>
</fieldType>

Any idea how to make Solr returns exact matches on suggest??

4

There are 4 answers

1
Abhijit Bashetti On

can you try with this

<fieldType name="textSpellShingle" class="solr.TextField" positionIncrementGap="100">
  <analyzer>
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="50" side="front"/>
    <filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="50" side="back"/>
  </analyzer>
</fieldType>
0
Christian A On

You are using the SpellChecker component, which, as the name indicate, is meant for spellchecking. It returns suggestions for how entry the should be spelled. When the word is spelled correct (which equals a exact match) it returns nothing, which is the reason you dont see the word in the list.

Since Solr 4.7 a new Suggestion component has been added, which is actually implemented for autosuggestion and yields the results you expect.

1
Nono On

Your problem came because you used the old suggest component based on the spellcheck component (I suppose you used a version of solr before 5).

With the old spellcheck/suggest, if the word match it is not return in the response!

Test with the solr.suggestComponent (if present in your version).

see: https://cwiki.apache.org/confluence/display/solr/Suggester

1
Jonathan Fortin On

As mentionned in this wiki page: https://cwiki.apache.org/confluence/display/solr/Suggester

To be used as the basis for a suggestion, the field must be stored.

Make sure your field is stored. You field isn't stored so it is returning the data crunched by your indexer.