Solr拼写检查建议始终返回0作为命中数

wswtfjt7  于 2022-11-05  发布在  Solr
关注(0)|答案(3)|浏览(181)

我使用SOLR的spellcheck组件来获取建议,并期望Hits部分返回新单词的一些匹配结果,但它在所有情况下都返回零个匹配结果:

{
   "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"
            ]
         ]
      ]
   }
}

我的设置是:

<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>

对于我的组件和

<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>

有什么想法,我可以得到这个填写,以便我可以显示#结果给最终用户?

cngwdvgl

cngwdvgl1#

可能有点晚了......我遇到了同样的问题,直到我意识到我必须显式地告诉Solr*运行*查询,这样它才能返回命中计数
您的requestHandler需要一个QueryComponent配置,默认的配置名为“query”,只需将其添加到您的requestHandler的 components 部分。

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

注意:如果请求处理程序具有defType参数集(指定要使用的查询解析器),则不需要执行此操作。

7tofc5zh

7tofc5zh2#

将以下内容添加到SearchHandler配置中,然后您将获得每个排序规则的命中计数:

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

**注意:**这将使排序器通过使用排序规则执行 * 实际查询 * 来验证排序规则,从而产生命中计数。为了使验证查询更快,它们禁用了计分和提升,并且也不加载任何存储字段,但排序器仍会为每个排序规则运行额外的查询-如果您的maxCollations设置较高,则需要注意这一点。

jv2fixgn

jv2fixgn3#

默认情况下,查询组件是执行链的一部分,因此不需要显式声明。

spellcheck.collateExtendedResults

设置为true,您将获得正确填充的numberOfHits和mispellingAndCorrections。

相关问题