问题描述
>>>营销 = User.search do |s|>>>s.fulltext营销">>>结尾>>>总营销1448>>>sales = User.search do |s|>>>s.fulltext "销售">>>结尾>>>总销售额567>>>Marketing_and_sales = User.search do |s|>>>s.fulltext "营销与销售">>>结尾>>>Marketing_and_sales.total945>>>Marketing_or_sales = User.search do |s|>>>s.fulltext "营销或销售">>>结尾>>>Marketing_or_sales.total945<Sunspot::Search:{:fq=>["type:User"], :q=>"Marketing AND Sales", :fl=>"* score", :qf=>"textfield1 textfield2textfield3", :defType=>"dismax", :start=>0, :rows=>30}>我想要简单的布尔查询来处理 sunspot-rails, solr我尝试了很多可能性,而不是简单地接受它.
AND 和 NOT 似乎按照 dismax 配置工作.我如何才能使 OR 查询正常工作.
提前致谢.
我想通了.您可以使用 any_of 和 all_of 指定搜索条件的范围.尽管 all_of 不起作用,除非在 any_of 中使用.这是链接 http://sunspot.github.com/docs/Sunspot/DSL/Scope.html#all_of-instance_method
>>>Marketing_or_sales = User.search do |s|>>>s.any_of 做>>>s.fulltext营销">>>s.fulltext "销售">>>结尾>>>结尾>>>Marketing_or_sales.total945>>> marketing = User.search do |s|
>>> s.fulltext "Marketing"
>>> end
>>> marketing.total
1448
>>> sales = User.search do |s|
>>> s.fulltext "Sales"
>>> end
>>> sales.total
567
>>> marketing_and_sales = User.search do |s|
>>> s.fulltext "Marketing AND Sales"
>>> end
>>> marketing_and_sales.total
945
>>> marketing_or_sales = User.search do |s|
>>> s.fulltext "Marketing OR Sales"
>>> end
>>> marketing_or_sales.total
945
<Sunspot::Search:{:fq=>["type:User"], :q=>"Marketing AND Sales", :fl=>"* score", :qf=>"textfield1 textfield2 textfield3", :defType=>"dismax", :start=>0, :rows=>30}>
I want simple boolean queries to get working on sunspot-rails, solrI tried many possibilities its not simply taking it.
The AND and NOT seems to be working as per the dismax configuration.How can i make OR query working.
Thanks in advance.
I figured it out. You can specify the scope of the search criterias using any_of and all_of . though all_of doesnt work unless used inside any_of . here is the link http://sunspot.github.com/docs/Sunspot/DSL/Scope.html#all_of-instance_method
>>> marketing_or_sales = User.search do |s|
>>> s.any_of do
>>> s.fulltext "Marketing"
>>> s.fulltext "Sales"
>>> end
>>> end
>>> marketing_or_sales.total
945
这篇关于如何在 sunspot solr 中进行简单的布尔查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!