10

我目前正在将 Apache Solr 搜索集成到我的平台中,并使用 Suggester 功能进行自动完成。但是,Suggester 模块也不返回拼写建议,例如,如果我搜索:

shi

建议模块返回以下内容:

shirt
shirts

但是,如果我搜索:

shrt

不返回任何建议。我想知道的是:

a) 是否是导致此问题的 Suggester 模块配置不正确?b) Suggester 模块是否以不返回拼写建议的方式构建?c) 我怎样才能让 Suggester 模块也返回拼写建议,而不必再次请求拼写更正建议?

我已经阅读了 Solr 文档,但似乎无法在这方面取得进展。

4

1 回答 1

10

您需要配置拼写检查组件以生成备用拼写选项,如https://lucene.apache.org/solr/guide/8_1/spell-checking.html中所述

该任务包括以下步骤:

首先,schema.xml使用拼写检查字段更新 。这通常意味着创建一个新字段并将多个字段复制到一个spellcheck字段:

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

<copyField source="id" dest="spellcheck"/>
<copyField source="name" dest="spellcheck"/>
<copyField source="description" dest="spellcheck"/>
<copyField source="longdescription" dest="spellcheck"/>
<copyField source="category" dest="spellcheck"/>
<copyField source="source" dest="spellcheck"/>
<copyField source="merchant" dest="spellcheck"/>
<copyField source="contact" dest="spellcheck"/>

solrconfig.xml更新您的请求处理程序并创建一个solr.SpellCheckComponent并将其添加到您的搜索处理程序中。

    <searchComponent name="spellcheck" class="solr.SpellCheckComponent">
      <lst name="spellchecker">
        <!-- decide between dictionary based vs index based spelling suggestions, 
        in most cases it makes sense to use index based spell checker
        as it only generates terms which are 
        actually present in your search corpus -->
        <str name="classname">solr.IndexBasedSpellChecker</str>
        <!-- field to use -->
        <str name="field">spellcheck</str>
        <!-- buildOnCommit|buildOnOptimize -->
        <str name="buildOnCommit">true</str>
        <!-- $solr.solr.home/data/spellchecker-->
        <str name="spellcheckIndexDir">./spellchecker</str>
        <str name="accuracy">0.7</str>
        <float name="thresholdTokenFrequency">.0001</float>
      </lst>
    </searchComponent>

    <requestHandler name="/select" class="solr.SearchHandler">
      <lst name="defaults">
        <str name="echoParams">explicit</str>
        <int name="rows">10</int>
        <str name="df">defaultSearchField</str>
        <!-- spell check component configuration -->
        <str name="spellcheck">true</str>
        <str name="spellcheck.count">5</str>
        <str name="spellcheck.collate">true</str>
        <str name="spellcheck.maxCollationTries">5</str>
      </lst>
      <!-- add spell check processing after 
        the default search component. This is 
        the search component name. -->
      <arr name="last-components">
        <str>spellcheck</str>
      </arr>
    </requestHandler>
  • 重新索引语料库

  • 测试建议正在发挥作用。例如,

http://localhost:8983/solr/select/?q=coachin

{
  "responseHeader": {
    "status": 0,
    "QTime": 12,
    "params": {
      "indent": "true",
      "q": "coachin"
    }
  },
  "response": {
    "numFound": 0,
    "start": 0,
    "docs": []
  },
  "spellcheck": {
    "suggestions": [
      "coachin", {
        "numFound": 1,
        "startOffset": 0,
        "endOffset": 7,
        "suggestion": ["cochin"]
      }
    ]
  }
}
于 2012-06-15T08:57:26.397 回答