如何使 solr 建议适用于特定领域?

How to make solr suggestion work for a specific field?

我正在尝试实现 solr 的自动建议,这是我在 solrconfig.xml 文件

中所做的更改
<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>
</lst>
<arr name="components">
  <str>suggest</str>
</arr>
</requestHandler>
<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">displayName</str>  <!-- the indexed field to derive suggestions from -->
  <float name="threshold">0.005</float>
  <str name="buildOnCommit">true</str>
</lst>
</searchComponent>

当我尝试使用示例输入进行查询时 'p'

http://localhost:8983/solr/food/suggest?q=p&wt=json&indent=true

它returns 5个字

"pizza", "potato", "pasta", "protein", "premium"

但是在 displayName 字段中,我得到了诸如 paneer 、 palak 等词,但没有显示为什么会这样?

您能否将以下内容添加到您的配置中并运行以下查询。 不要忘记在进行这些更改后重新加载 solr 核心。

<str name="suggestAnalyzerFieldType">string</str>
<str name="storeDir">suggester_fuzzy_dir</str>

http://localhost:8983/solr/food/suggest?suggest=true&suggest.build=true&suggest.dictionary=suggest&wt=json&suggest.q=p&suggest.count=10