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

I want simple boolean queries to get working on sunspot-rails, solr I 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.

Krishna Prasad Varma
  • 4,670
  • 5
  • 29
  • 41

1 Answers1

3

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  
Krishna Prasad Varma
  • 4,670
  • 5
  • 29
  • 41
  • 1
    Does it really work for you? The doc claims that any_of and all_of only works for scalar fields, eg. string, integer etc. From my observation there is no difference between call any_of or all_of for fulltext fields. The query is the same, so in fact sunspot just ignores any_of or all_of for fulltext fields. – wawka Mar 21 '14 at 13:48