e x p r e s s i c a

ruby on rails, business and technicalities

No public Twitter messages.

  • RSS
  • Facebook
  • Twitter
  • Linkedin

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", :o perator => :o r)

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", :o perator => :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)")

One Response so far.

  1. acts author says:

    [...] Acts as solr: Logical Search [...]


Sponsors