我有以下问题: 我有一个带有多个索引的Solr核心。我的网站上有3种不同的搜索类型:
我有Nr.3的自动提示。到目前为止,1和2没有任何建议。但是我想为汽车实施一个额外的建议,所以当我想只搜索汽车时,建议者会告诉我只属于汽车而不是dvds等的单词。我正在考虑新的requestHandler并执行搜索,因为我需要这两个特定字段来填充Nr.3搜索通过字典自动填充的建议。 是否有可能在一个Solr Core中有两个或更多不同的建议者?如何针对特定搜索类型使用特定字段进行自动填充和建议,以便在这些建议中仅列出汽车属性?
先谢谢!
答案 0 :(得分:3)
当然,可以做到。只需设置两个搜索组件,如下所示:
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">suggest_cars</str>
<str name="lookupImpl">BlendedInfixLookupFactory</str>
<str name="blenderType">linear</str>
<str name="dictionaryimpl">DocumentDictionaryFactory</str>
<str name="field">cars_suggest</str>
<str name="weightField">popularity</str>
<str name="suggestAnalyzerFieldType">text_suggest</str>
<str name="queryAnalyzerFieldType">phrase_suggest</str>
<str name="indexPath">cars_suggest</str>
<str name="buildOnStartup">false</str>
<str name="buildOnCommit">false</str>
<bool name="exactMatchFirst">true</bool>
</lst>
<lst name="suggester">
<str name="name">suggest_all</str>
<str name="lookupImpl">BlendedInfixLookupFactory</str>
<str name="blenderType">linear</str>
<str name="dictionaryimpl">DocumentDictionaryFactory</str>
<str name="field">suggest</str>
<str name="weightField">popularity</str>
<str name="suggestAnalyzerFieldType">text_suggest</str>
<str name="queryAnalyzerFieldType">phrase_suggest</str>
<str name="indexPath">all_suggest</str>
<str name="buildOnStartup">false</str>
<str name="buildOnCommit">false</str>
<bool name="exactMatchFirst">true</bool>
</lst>
然后创建一个请求处理程序:
<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="echoParams">all</str>
<str name="wt">json</str>
<str name="indent">false</str>
<str name="suggest">true</str>
<str name="suggest.count">10</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
在schema.xml文件中,这两个字段类型:
<fieldType name="phrase_suggest" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.TrimFilterFactory"/>
</analyzer>
</fieldType>
<fieldType name="text_suggest" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ASCIIFoldingFilterFactory"/>
<filter class="solr.EnglishPossessiveFilterFactory"/>
</analyzer>
</fieldType>
当然,您需要两个字段cars_suggest和all_suggest,分别包含汽车和汽车/ DVD的建议条款,字段类型为phrase_suggest(即使用关键字标记器)。
查询完成如下:
http://localhost:8983/solr/collection0/suggest?q=peug&suggest.dictionary=suggest_cars