« Haml and Rails rendering speed | Home | XMPP4R and setting a VCard in Ruby on Rails »

Faceted search in Solr with Ruby on Rails

By Nick | July 13, 2007

Solr is a powerful, easy to use search framework build on top of Lucene. It currently powers the search of my RailsHostingInfo.com page. And it makes the nice faceting (grouping of data) possible. Recently I got the question how to do it with acts_as_solr. Well the truth is, I don’t know. I haven’t used acts_as_solr. But this is what I got from the rdocs at http://acts-as-solr.rubyforge.org/. You should use find_with_facet, like so, with facets obviously being your categories:

Electronic.find_with_facet “memory”, :facets => {:query => ["price:[* TO 200]“,
“price:[200 TO 500]“,
“price:[500 TO *]“],
:fields => [:category, :manufacturer]}

For my purposes (using Solr 1.1) I add the following parameters to the query url: “&facet=true&facet.field=plan_type&facet.field=company_server_location&facet.zeros=false”

For more information about using facets in Solr, take a look at the Solr wiki: http://wiki.apache.org/solr/SimpleFacetParameters. That gives you all the details about facets in Solr.

Topics: Uncategorized |