There are a couple of ways described in acts_as_solr documentation for the logical search, with AND or OR operations. But I needed to dig a bit into the code as the documentation is not complete and doesn’t suggest all the possible implementations of making the complex Logic Gates for searching.
Here I am consolidating various possibilities of Logical Search…
Find all blogs with category ruby or rails
Blog.find_by_solr("category:rails category:ruby", :operator => :or)
another way
Blog.find_by_solr("category:rails OR category:ruby")
Find all blogs with categories ruby and rails
Blog.find_by_solr("category:rails category:ruby", :operator => :and)
another way
Blog.find_by_solr("category:rails AND category:ruby")
Grouping for more precision
NOTE: mind the grouping using parenthesis, you might get unexpected results without proper grouping.
Find all blogs with categories ruby or rails with author Sur
Blog.find_by_solr("(category:rails OR category:ruby) author:sur")
Find all blogs with categories ruby AND rails with author Sur
Blog.find_by_solr("(category:rails AND category:ruby) author:sur")
Find all blogs with categories ruby or rails with author Sur or David
Blog.find_by_solr("(category:rails OR category:ruby) (author:sur OR author:David)")
Find all blogs with categories ruby and rails with author Sur or David
Blog.find_by_solr("(category:rails AND category:ruby) (author:sur OR author:David)")
Filed in: acts_as_solr, logical_search

