Solr能精准搜索关键词吗?
例如: 我想搜索“support”,我希望它只返回包含“support”的结果,而不返回包含“supports”或任何其他相关匹配项的结果。
这样的实现可以吗?
谢谢。
For example:
I want to search "support", I hope it will only return the results containing "support", and do NOT return the result containing "supports" or any other relevant matches.
Is it possible to implement like this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,如果您搜索未分析的字段类型,则匹配是精确的。在默认的 Solr 模式中,未分析的字段类型被命名为“string”(属于“solr.StrField”类)
编辑:这取决于“精确”的含义。如果您的字段值是“支持台”并且您的查询是“支持”,它应该匹配吗?
此外,如果您的查询是“supports”并且字段值为“Supports”,它应该匹配吗?
总之,Lucene/Solr 文本分析管道是非常可配置的,请查看分析器文档以供所有参考可用选项。
Yes, if you search against an unanalyzed field type, matches are exact. In the default Solr schema the unanalyzed field type is named "string" (of class "solr.StrField")
EDIT: it depends on what you mean by "precisely". If your field value is "support desk" and your query is "support", should it match?
Furthermore, if your query is "supports" and the field value is "Supports", should it match?
In summary, the Lucene/Solr text analysis pipeline is very configurable, take a look at the analyzer docs for a reference of all available options.
您所描述的称为词干。关于堆栈溢出还有另一个几乎相同的问题,请查看:Solr 精确单词搜索
您将需要在配置中重新索引并禁用词干提取。我不认为在查询时可以做到这一点,因为存储在索引中的是单词的词干版本。在您的情况下,即使显示“支持”,“支持”也存储在索引中。
这应该可以帮助您开始如何在 Solr 中配置词干分析?
What you are describing is called stemming. There is another almost identical question on stack overflow, check it out : Solr exact word search
You will need to re-index and disable stemming in your configuration. I don't believe it's possible to do that at query time since what is stored in your index is the stemmed version of the word. In your case "support" is stored in the index even is "supports" is displayed.
This should get you started How to configure stemming in Solr?