Question

I am using SOLR's spellcheck component to get suggestions and expected the Hits part to return a number of hits from the new words but it returns zero hits in all cases:

    {
   "spellcheck":{
      "suggestions":[
         "pho",
         {
            "numFound":8,
            "startOffset":0,
            "endOffset":3,
            "suggestion":[
               "photo",
               "phone",
               "phone's",
               "phones",
               "photography",
               "photoimpression's",
               "photographers",
               "photos"
            ]
         },
         "collation",
         [
            "collationQuery",
            "photo",
            "hits",
            0,
            "misspellingsAndCorrections",
            [
               "pho",
               "photo"
            ]
         ],
         "collation",
         [
            "collationQuery",
            "phone",
            "hits",
            0,
            "misspellingsAndCorrections",
            [
               "pho",
               "phone"
            ]
         ],
         "collation",
         [
            "collationQuery",
            "phone's",
            "hits",
            0,
            "misspellingsAndCorrections",
            [
               "pho",
               "phone's"
            ]
         ],
         "collation",
         [
            "collationQuery",
            "phones",
            "hits",
            0,
            "misspellingsAndCorrections",
            [
               "pho",
               "phones"
            ]
         ],
         "collation",
         [
            "collationQuery",
            "photography",
            "hits",
            0,
            "misspellingsAndCorrections",
            [
               "pho",
               "photography"
            ]
         ],
         "collation",
         [
            "collationQuery",
            "photoimpression's",
            "hits",
            0,
            "misspellingsAndCorrections",
            [
               "pho",
               "photoimpression's"
            ]
         ],
         "collation",
         [
            "collationQuery",
            "photographers",
            "hits",
            0,
            "misspellingsAndCorrections",
            [
               "pho",
               "photographers"
            ]
         ],
         "collation",
         [
            "collationQuery",
            "photos",
            "hits",
            0,
            "misspellingsAndCorrections",
            [
               "pho",
               "photos"
            ]
         ]
      ]
   }
}

My settings are:

<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.tst.TSTLookupFactory</str>
        <str name="field">text</str>
        <float name="threshold">0.005</float>
        <str name="buildOnCommit">true</str>
    </lst>
</searchComponent>

For my component and

<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">true</str>
        <str name="spellcheck.maxCollations">10</str>
        <str name="spellcheck.collateExtendedResults">true</str>
    </lst>
    <arr name="components">
        <str>suggest</str>
    </arr>
</requestHandler>

Any ideas on how I could get this filled in so I could show the #results to the end-user?

Was it helpful?

Solution

Probably a bit late... I had the same problem until I realized that I have to explicitly tell Solr to run the query so it can return hits count.

Your requestHandler needs a QueryComponent config, the default one is named "query", just add it to your requestHandler's components section.

<arr name="components">
  <str>query</str>
  <str>suggest</str>
</arr>

Note: This is not needed if the request handler has a defType param set (specifying which query parser to use).

OTHER TIPS

Add the following to the SearchHandler config, and then you'll get per-collation hitcounts:

<str name="spellcheck.maxCollationTries">1</str>

Note: This will make the collator verify the collations by doing actual queries using them, thus producing hitcounts. To make the verification queries fast they have scoring and boosting disabled, and also don't load any stored fields, but the collator is still running an extra query per collation - something to be aware of if you have a high maxCollations setting.

The query component is by default part of the execution chain and therefore doesn't need to be declared explicitly. What you need is

spellcheck.collateExtendedResults

set to true, and you will get the numberOfHits and mispellingAndCorrections properly populated. As pointed in other answers, this adds a consistent overhead

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