0

I have a schemaless solr core with inferred data types in managed-schema.xml as:

<field name="Name" type="text_general" indexed="true" stored="true"/>
<field name="Type" type="text_general" indexed="true" stored="true"/>

I added on a new field:

<field name="didYouMean" type="text_general" indexed="true" multiValued="true" stored="true"/>

Which is a copyfield of:

<copyField source="Name" dest="didYouMean"/>
<copyField source="Type" dest="didYouMean"/>

In solrconfig.xml, I have the search component as:

<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
    <lst name="spellchecker">
        <str name="name">default</str>
        <str name="field">didYouMean</str>
        <str name="classname">solr.DirectSolrSpellChecker</str>
        <float name="accuracy">0.5</float>
        <int name="minPrefix">1</int>
        <int name="minQueryLength">3</int>     
    </lst>   
</searchComponent>

However, when I tried searching for an entry like Name:reffles, solr gives this response:

{
  "responseHeader":{
    "status":0,
    "QTime":1},
  "response":{"numFound":0,"start":0,"numFoundExact":true,"docs":[]
  },
  "spellcheck":{
    "suggestions":[],
    "collations":[]}}

The correct response should have been "raffles" instead.

In contrast, I used another configuration for the search component by using the search field to be "Name" as shown below:

<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
    <lst name="spellchecker">
        <str name="name">default</str>
        <str name="field">Name</str>
        <str name="classname">solr.DirectSolrSpellChecker</str>
        <float name="accuracy">0.5</float>
        <int name="minPrefix">1</int>
        <int name="minQueryLength">3</int>
    </lst>
</searchComponent>

I get the correct response:

{
  "responseHeader":{
    "status":0,
    "QTime":35},
  "command":"build",
  "response":{"numFound":0,"start":0,"numFoundExact":true,"docs":[]
  },
  "spellcheck":{
    "suggestions":[
      "reffles",{
        "numFound":1,
        "startOffset":5,
        "endOffset":12,
        "suggestion":["raffles"]}],
    "collations":[
      "collation",{
        "collationQuery":"Name:raffles",
        "hits":1,
        "misspellingsAndCorrections":[
          "reffles","raffles"]}]}}

-----

The configurations were the same. On solr admin, only the spellcheck and spellcheck.build boxes are checked.

I have looked into other stackoverflow pages like Solr/Lucene spellcheck suggestions based on multiple fields https://sitecore.stackexchange.com/questions/2244/how-to-implement-did-you-mean-spell-checker-functionality-like-google-in-si


The solution is to do reindexing on the new schema.

  1. Delete all existing data from solr collection
  2. Reindex it again by posting the documents to solr

Useful sites: Delete all solr data, Solr Reindexing

kcv
  • 1
  • 1
  • Did you reindex after adding the new field ? If not then your field remains empty, hence no suggestion. See this [post](https://stackoverflow.com/a/46049307/2529954). – EricLavault Mar 12 '23 at 17:37

0 Answers0