如何在 Solr 5.3.0 中获得建议 [英] How to get Suggestions in Solr 5.3.0

查看:17
本文介绍了如何在 Solr 5.3.0 中获得建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Solr 5.3.0 实现自动完成功能

I am trying to implement auto complete feature using Solr 5.3.0

solrconfig.xml 看起来像这样

solrconfig.xml looks like this

<searchComponent name="suggest" class="solr.SuggestComponent">
  <lst name="suggester">
    <str name="name">default</str>
    <str name="lookupImpl">FuzzyLookupFactory</str>
    <str name="dictionaryImpl">DocumentDictionaryFactory</str>
    <str name="field">suggest_ngram</str>
    <str name="weightField">price</str>
    <str name="suggestAnalyzerFieldType">text_suggest_ngram</str>
    <str name="buildOnStartup">true</str>
  </lst>
</searchComponent>

<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy" >
<lst name="defaults">
  <str name="suggest">true</str>
  <str name="suggest.count">10</str>
</lst>
<arr name="components">
  <str>suggest</str>
</arr>

托管架构如下所示:

<fieldType name="text_suggest_ngram" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
  <filter class="solr.LowerCaseFilterFactory"/>
  <filter class="solr.EdgeNGramFilterFactory" maxGramSize="10" minGramSize="2" />
</analyzer>
<analyzer type="query">
  <tokenizer class="solr.StandardTokenizerFactory"/>
  <filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>


<field name="suggest_ngram" type="text_suggest_ngram" indexed="true" stored="false"/>
<field name="name" type="string" multiValued="false" indexed="true" stored="true"/>
<field name="price" type="tlong" multiValued="false" indexed="true" stored="true"/>
<copyField source="name" dest="suggest_ngram"/>

现在,当我从 Solr 的管理面板使用分析器时,我可以看到索引的 ngram.它成功地指出了匹配.

Now when I use the analyzer from the admin panel of Solr, I can see the indexed ngrams. And it successfully points out the match.

但是当我使用查询时:

http://localhost:8983/solr/products/suggest?suggest=true&suggest.build=true&wt=json&suggest.q=Jind

我收到了 0 条建议.回复在这里:https://api.myjson.com/bins/47r3i

I get 0 suggestions. The response is here: https://api.myjson.com/bins/47r3i

在其中一个文档中,名称键存在一个值Jindal Panther".

There exists a value "Jindal Panther" for the name key in one of the docs.

此外,我发现如果我创建一个类型为String"、源为name"的虚拟复制字段suggest",任何对name"有效的建议都不适用于suggest".这可能是复制字段的任何错误配置以启用建议吗?

Moreover, I have found that if I create a dummy copyfield "suggest" with type as "String", with source as "name", any suggestion that works fine on "name" will not work on "suggest". Can this be any misconfiguration of copyfield to enable suggestions?

任何帮助将不胜感激.提前致谢.

Any help would be appreciated. Thanks in advance.

得到了解决方案.请参阅下面的已接受答案及其评论.我遇到的一个博客很好地解释了 Suggesters.对于 Solr Search 的新手来说,绝对值得一读.

Got the solution. See the accepted answer and its comments below. There is a blog that I encountered that beautifully explains Suggesters. It is definitely worth reading for a newbie to Solr Search.

https://lucidworks.com/blog/2015/03/04/solr-suggester/

推荐答案

您要配置建议器的字段应为 store=true.它不需要被索引.建议器配置将根据 suggestComponet 中的提供配置构建字典.name 字段已存储为 truesuggest_ngram 不是.您需要像这样更新架构配置:

The field on which you want to configure the suggester should be store=true. It need not to be indexed. The suggester configuration will build a dictionary according to the provide configuration in the suggestComponet. The name field have stored as true where as suggest_ngram is not. You need to update the schema configuration like this:

<field name="suggest_ngram" type="text_suggest_ngram" indexed="false" stored="true"/>

此外,您还需要提供参数 suggest.dictionary,即用于提供建议的字典.对您来说,它的名称为 default.

Also you need to provide the parameter suggest.dictionary, the dictionary you are using for suggestions. For you it is names as default.

http://localhost:8983/solr/products/suggest?suggest=true&
       suggest.build=true&
       wt=json&
       suggest.dictionary=default&
       suggest.q=Jind

或者你可以在/suggestrequestHandler中提供字典配置:

OR you can provide the dictionary configuration in requestHandler of /suggest:

<str name="suggest.dictionary">default</str>

这篇关于如何在 Solr 5.3.0 中获得建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆