0

I have created 2 nodes having 2 shards in Solr. I am doing spell correction technique. I want to sort the suggestions of query(abple) on the basis on frequency. By default, it is sorting on score(Levenshtein Distance).

I added <str name="comparatorClass">freq</str> in solr.SpellCheckComponent of solrconfig.xml. But still, it is not working.

Current suggestions are sorted on score (Not required):

"suggestion":[{
            "word":"apple",
            "freq":23},
          {
            "word":"ample",
            "freq":5},
          {
            "word":"abele",
            "freq":3},
          {
            "word":"able",
            "freq":176}}]

Require suggestions to sort on frequency (Required):

"suggestion":[{
            "word":"able",
            "freq":176}},
          {
            "word":"apple",
            "freq":23},
          {
            "word":"ample",
            "freq":5},
          {
            "word":"abele",
            "freq":3}}]

Configurations files:

solrconfig.xml:

<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
    <str name="queryAnalyzerFieldType">textSpellCi</str>
    <lst name="spellchecker">
      <str name="name">default</str>
      <str name="field">gram_ci</str>
      <str name="classname">solr.DirectSolrSpellChecker</str>
      <str name="distanceMeasure">internal</str>
      <float name="accuracy">0.5</float>
      <int name="maxEdits">2</int>
      <int name="minPrefix">0</int>
      <int name="maxInspections">5</int>
      <int name="minQueryLength">2</int>
      <float name="maxQueryFrequency">0.9</float>
      <str name="comparatorClass">freq</str>
    </lst>
</searchComponent>

<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
    <lst name="defaults">
      <str name="df">gram_ci</str>
      <str name="spellcheck.dictionary">default</str>
      <str name="spellcheck">on</str>
      <str name="spellcheck.extendedResults">true</str>
      <str name="spellcheck.count">25</str>
      <str name="spellcheck.onlyMorePopular">true</str>
      <str name="spellcheck.maxResultsForSuggest">100000000</str>
      <str name="spellcheck.alternativeTermCount">25</str>
      <str name="spellcheck.collate">true</str>
      <str name="spellcheck.maxCollations">50</str>
      <str name="spellcheck.maxCollationTries">50</str>
      <str name="spellcheck.collateExtendedResults">true</str>
    </lst>
    <arr name="last-components">
      <str>spellcheck</str>
    </arr>
  </requestHandler>

Schema.xml:

<field name="gram_ci" type="textSpellCi" indexed="true" stored="true" multiValued="false"/>

</fieldType><fieldType name="textSpellCi" class="solr.TextField" positionIncrementGap="100">
       <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ShingleFilterFactory" maxShingleSize="5" minShingleSize="2" outputUnigrams="true"/>
</analyzer>
    <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ShingleFilterFactory" maxShingleSize="5" minShingleSize="2" outputUnigrams="true"/>
</analyzer>
</fieldType>
iNikkz
  • 3,729
  • 5
  • 29
  • 59

2 Answers2

2

I faced similar problem but it worked for me making the change you mentioned:

<str name="comparatorClass">freq</str>

You may not have restarted your solr instance. Try doing that first.

user2627846
  • 413
  • 4
  • 17
  • Confirmed this works when added to the searchComponent spellchecker setup, thank you (Solr 7.2.0). – seb835 May 13 '22 at 11:03
0

Try after adding this param to your search handler:

<str name="spellcheck.onlyMorePopular">true</str>

Rajesh
  • 83
  • 11
  • Can you share your config? – Rajesh Feb 10 '15 at 14:28
  • I want to do spell/query correction functionality. I have 49 GB indexed data where I have applied spellchecker. I want to do same as Google - "did you mean". Example - If any user types any question/query which might be misspell or wrong typed. I need to give them suggestion like "Did you mean". Is Solr best for it? – iNikkz Feb 23 '15 at 16:24