solr - 多个术语短语的 SOLR 自动完成
问题描述
我在 Solr 中有一个关于自动完成的问题 - 说有一个多词字符串“nice Cheap laptop”,如果他们输入“nice”、“cheap”或“laptop”,应该向用户建议。如何使用 Solr 实现这一目标?
我正在尝试将当前与 ElasticSearch 一起使用的代码迁移到 SOLR - 对于 ES,映射提供了“完成”类型,为此我将短语中术语的所有排列配置为要搜索的输入,输出是原话。在文档中找不到 SOLR 是否/如何实现这一点。
编辑:
我尝试将以下内容添加到 solrconfig.xml:
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">mySuggester</str>
<str name="lookupImpl">FuzzyLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">name</str>
<!--str name="weightField">price</str-->
<str name="suggestAnalyzerFieldType">string</str>
<str name="buildOnStartup">false</str>
</lst>
</searchComponent>
<requestHandler name="/suggest" class="solr.SearchHandler"
startup="lazy" >
<lst name="defaults">
<str name="suggest.dictionary">mySuggester</str>
<str name="suggest">true</str>
<str name="suggest.count">10</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
以下是托管架构:
<field name="productNameId" type="string" indexed="true" stored="true"/>
<field name="aspectId" type="pint" indexed="true" stored="true"/>
<field name="name" type="text_general" indexed="true" stored="true"/>
<field name="categoryId" type="string" indexed="true" stored="true"/>
然后用 solrj 索引 3 个文档:
String urlString = "http://localhost:8983/solr/aspects";
HttpSolrClient client = new HttpSolrClient.Builder(urlString).build();
client.setParser(new XMLResponseParser() );
ProductAspects pa1 = new ProductAspects();
pa1.setId("1");
pa1.setAspectId(1);
pa1.setName("alice");
ProductAspects pa2 = new ProductAspects();
pa2.setId("2");
pa2.setAspectId(2);
pa2.setName("alza");
ProductAspects pa3 = new ProductAspects();
pa3.setId("3");
pa3.setAspectId(3);
pa3.setName("alza bob");
final UpdateResponse res1 = client.addBean( pa1 );
final UpdateResponse res2 = client.addBean( pa2 );
final UpdateResponse res3 = client.addBean( pa3 );
UpdateResponse res = client.commit();
在那之后,我希望输入“alz”只会返回 2 个文档,但它会返回所有 3 个文档:
http://localhost:8983/solr/aspects/suggest?suggest.dictionary=mySuggester&suggest=true&suggest.build=true&suggest.q=alz
您能否帮助使用 Solr 进行自动完成的正确配置是什么?
解决方案
推荐阅读
- macos - 如何在终端脚本中连接字符串变量
- github - OAuth 个人令牌访问组织的私人仓库:错误的身份验证错误
- amazon-web-services - 如何将环境变量添加到 CDK 中的 CloudFront 函数?
- node.js - 如何修复 docker-compose 中的 FileNotFoundError
- html - 在一个显示器中组合多个线性渐变
- r - 计算数据框中组行的频率
- python - 模型输出在不同平台上略有不同是否正常?
- php - 在分页类别博客文章上重定向
- python - kmeans结果上的Python DataFrame groupby不显示所有类别
- reactjs - ag-Grid 在列单元格上禁用多列排序渲染器单击