基于多个字段的 Solr/Lucene 拼写检查建议
我有一个包含供应商信息的数据库:名称和地址(地址、城市、邮政编码和国家/地区字段)。我需要搜索这个数据库并返回一些供应商。在搜索框中,用户可以输入任何内容:供应商名称、地址的一部分、城市、邮政编码……并且,如果我找不到任何结果,我需要实现一个谷歌,例如“您是说“吗? ”功能向用户提供建议。
我考虑过使用Solr/Lucene来做到这一点。我已经安装了 Solr,使用 CSV 文件导出了我需要的信息,并基于该文件创建了索引。现在我可以使用 solr.SpellCheckComponent 从 Solr 字段获取建议。问题是我的建议基于单个字段,需要它从地址、城市、邮政编码、国家/地区和名称字段中获取信息。
在 solr 配置文件上,我有这样的内容:
<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
<str name="queryAnalyzerFieldType">textSpell</str>
<lst name="spellchecker">
<str name="name">default</str>
<str name="field">name</str>
<str name="spellcheckIndexDir">spellchecker</str>
</lst>
</searchComponent>
<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="spellcheck.onlyMorePopular">false</str>
<str name="spellcheck.extendedResults">false</str>
<str name="spellcheck.count>1</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
</arr>
</requestHandler>
我可以运行如下查询:
http://localhost:8983/solr/spell?q=some_company_name&spellcheck=true&spellcheck.collate=true&spellcheck.build=true
有谁知道如何更改我的配置文件以便从多个字段获得建议?
谢谢!!!
I have a database with Vendor's information: name and address (address, city, zip and country fields). I need to search this database and return some vendors. On the search box, the user could type anything: name of the vendor, part of the address, city, zip,... And, if I can't find any results, I need to implement a google like "Did you mean" feature to give a suggestion to the user.
I thought about using Solr/Lucene to do it. I've installed Solr, exported the information I need using CSV file and created the indexes based on this file. Now I am able to get suggestions from a Solr field using solr.SpellCheckComponent. The thing is my suggestion is based in a single field and need it to get information from address, city, zip, country and name fields.
On solr config file I have something like this:
<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
<str name="queryAnalyzerFieldType">textSpell</str>
<lst name="spellchecker">
<str name="name">default</str>
<str name="field">name</str>
<str name="spellcheckIndexDir">spellchecker</str>
</lst>
</searchComponent>
<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="spellcheck.onlyMorePopular">false</str>
<str name="spellcheck.extendedResults">false</str>
<str name="spellcheck.count>1</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
</arr>
</requestHandler>
I can run queries like:
http://localhost:8983/solr/spell?q=some_company_name&spellcheck=true&spellcheck.collate=true&spellcheck.build=true
Does anyone know how to change my config file in order to have suggestions from multiple fields?
Thanks!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了将 Solr 拼写检查配置为使用多个字段中的单词,您应该:
。>
。didYouMean
。有关更多详细信息,请访问来自多个领域的 Solr 拼写检查复合
In order to configure Solr spellcheck to use words from several fields you should:
<field name="didYouMean" type="textSpell" indexed="true" multiValued="true"/>
.<copyField source="field1" dest="didYouMean"/>
.<copyField source="field2" dest="didYouMean"/>
<str name="field">didYouMean</str>
.For more and detailed information visit Solr spellcheck compound from several fields
您可以在 schema.xml 中使用 copyfield 来实现此目的。
会将所有字段复制到 contentSpell。然后将
name
更改为contentSpell
即可获取各领域的建议。You use copyfield for this in schema.xml.
<copyField source="*" dest="contentSpell"/>
will copy all the fields to contentSpell.Then change
<str name="field">name</str>
to<str name="field">contentSpell</str>
en you will get suggestions from all fields.