使用 solr 改进搜索结果 +太阳黑子
我想知道是否有什么我可以做的来帮助改善我在 solr 中看到的搜索结果。
我有一个产品模型,其文本字段“名称”的值为“The Glenlivet 18 Year”。
我的产品模型中有此可搜索块:
searchable do
text :name
end
当我搜索“The Glenlivet Single Malt Scotch 18 Yr. 750ML”时,我得到零结果。
1.9.3-p0 :001 > Product.search { fulltext "The Glenlivet Single Malt Scotch 18 Yr. 750ML"}.results
=> []
看来我必须真正简化搜索查询才能获得结果,这不是很有用。
1.9.3-p0 :002 > Product.search { fulltext "The Glenlivet 18 Yr. 750ML"}.results
=> []
1.9.3-p0 :006 > Product.search { fulltext "The Glenlivet Single Malt 18"}.results
=> []
看起来这个确实应该有用。
1.9.3-p0 :003 > Product.search { fulltext "The Glenlivet 18 Yr."}.results
=> []
最后
1.9.3-p0 :007 > Product.search { fulltext "Glenlivet 18"}.results
Product Load (0.2ms) SELECT `products`.* FROM `products` WHERE `products`.`id` IN (8)
=> [#<Product id: 8, name: "The Glenlivet 18 year"]
是 sunspot_solr gem 创建的 solr 中的所有默认设置。这是我的配置文件:
与这些从结果来看,它几乎违背了全文搜索的目的。是否有任何我可以调整的设置或其他任何我可以做的事情,以使这些结果看起来不那么严格?
编辑:
添加 :minimum_match => 4
并设置同义词似乎提供了我想要的结果。
Product.search { fulltext "The Glenlivet Single Malt Scotch 18 Yr. 750ML", :minimum_match => 4}.results
I'm wondering if there was anything I could do help improve a search result I'm seeing with solr.
I have a Product model with a text field "name" with the value "The Glenlivet 18 year".
I have this searchable block in my Product model:
searchable do
text :name
end
When I search for "The Glenlivet Single Malt Scotch 18 Yr. 750ML", I get zero results.
1.9.3-p0 :001 > Product.search { fulltext "The Glenlivet Single Malt Scotch 18 Yr. 750ML"}.results
=> []
It seems like I have to really boil down the search query to get a result, which isn't very useful.
1.9.3-p0 :002 > Product.search { fulltext "The Glenlivet 18 Yr. 750ML"}.results
=> []
1.9.3-p0 :006 > Product.search { fulltext "The Glenlivet Single Malt 18"}.results
=> []
It really seams like this one should work.
1.9.3-p0 :003 > Product.search { fulltext "The Glenlivet 18 Yr."}.results
=> []
Then finally
1.9.3-p0 :007 > Product.search { fulltext "Glenlivet 18"}.results
Product Load (0.2ms) SELECT `products`.* FROM `products` WHERE `products`.`id` IN (8)
=> [#<Product id: 8, name: "The Glenlivet 18 year"]
It's all the default settings in solr that the sunspot_solr gem creates. Here are my config files:
With these kind of results it pretty much defeats the purpose of full text search. Are there any settings I can tweak or anything else I can do so that these results don't seem as strict?
Edit:
Adding the :minimum_match => 4
and setting the synonyms seems to provide the results I want.
Product.search { fulltext "The Glenlivet Single Malt Scotch 18 Yr. 750ML", :minimum_match => 4}.results
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您的全文字段被视为文本而不是字符串,然后查看最小匹配设置:
http://wiki.apache.org/solr/DisMaxQParserPlugin#mm_.28Minimum_.27Should.27_Match.29
另外,您可能需要同义词来使年份和年份相等。
Make sure your fullext field is treated as text and not a string then look at the minimum match setting:
http://wiki.apache.org/solr/DisMaxQParserPlugin#mm_.28Minimum_.27Should.27_Match.29
Also, you might need synonym to equate year and yr.