我正在尝试在product_name字段上使用 Solr 6.6 和Spring Boot实现自动建议功能。我在核心中给出了以下记录。
{"id":"xsku2023","type":"0","name":"Retro Lamp","product_id":"xprod2023","product_name":"Bajaj Lamp","product_type":"null","product_description":"Cheap and Best Lamp","listPrices":"65","plist3080002":"39.99","inventory_status":"In Stock","category_id":"catTableLamps","category_name":"TableLamps","category_href":"null","category_parent":"null","brand":"Bajaj"},
{"id":"xsku2024","type":"0","name":"Retro Lamp","product_id":"xprod2024","product_name":"Bajaj Table Lamp","product_type":"null","product_description":"Cheap and Best Table Lamp","listPrices":"65","plist3080002":"39.99","inventory_status":"In Stock","category_id":"catTableLamps","category_name":"TableLamps","category_href":"null","category_parent":"null","brand":"Bajaj"}
我已将/ suggest端点定义为已定义here并正在使用
我能够实现基本的建议功能。
http://localhost:8983/solr/ProductATG/suggest?suggest=true&suggest.build=true&suggest.dictionary=productSuggester&wt=json&suggest.q=Baj
获得以下响应,当点击上面的URL时,这是完全正常的,我得到的产品名称以查询中提供的前缀I开头。
{"responseHeader":{"status":0,"QTime":8},"command":"build","suggest":{"productSuggester":{"Baj":{"numFound":2,"suggestions":[{"term":"Bajaj Lamp","weight":0,"payload":""},{"term":"Bajaj Table Lamp","weight":0,"payload":""}]}}}}
现在,我想进入下一个级别并希望实现结果,无论顺序如何。对于前者
Solr指数中可用的产品名称 - “Bajaj Lamp”,“Bajaj台灯”
如果我搜索灯,产品名称“Bajaj Lamp”,“Bajaj台灯”目前应该响应,如果我搜索Lamp没有找到结果是来
答案 0 :(得分:0)
我已经弄明白了如何进行无序搜索。这可以通过使用AnalyzingInfixLookupFactory
来实现。 AnalyzingInfixLookupFactory可以进行中缀搜索。
的 solrconfig.xml中强>
<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>
</requestHandler>
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">productSuggester</str>
<!--<str name="lookupImpl">FuzzyLookupFactory</str> -->
<str name="lookupImpl">AnalyzingInfixLookupFactory</str> -->
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">product_name</str>
<!-- <str name="weightField">price</str> -->
<str name="buildOnCommit">true</str>
<str name="suggestAnalyzerFieldType">text_suggest</str>
<str name="buildOnStartup">true</str>
<str name="highlight">false</str>
</lst>
</searchComponent>
<!-- Added for testign AnalyzingInfixLookupFactory -->
<str name="queryAnalyzerFieldType">text_suggest</str>
<强>管理型模式强>
<fieldtype name="text_suggest" class="solr.TextField">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory" />
<filter class="solr.ASCIIFoldingFilterFactory"/>
</analyzer>
</fieldtype>