3
>>> 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}>

我想要简单的布尔查询来处理太阳黑子轨道,我尝试了很多可能性,而不是简单地接受它。

AND 和 NOT 似乎按照 dismax 配置工作。我怎样才能使 OR 查询工作。

提前致谢。

4

1 回答 1

3

我想到了。您可以使用 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 do 
>>>         s.fulltext "Marketing"
>>>         s.fulltext "Sales"
>>>     end
>>> end
>>> marketing_or_sales.total
945  
于 2012-08-20T12:50:33.103 回答