tag:selfsolved.com,2005:/problems/multivalue-facet-fields-in-acts_/sSolutions for: multivalue facet fields in acts_as_solr | SelfSolveda SelfSolved feed2009-07-24T19:47:32Z1SelfSolvedtag:selfsolved.com,2005:Array/69923141849340kueda Let's assume you have a Species model that has many associated Colors.
The thing that was throwing me was that I wasn't specifying the type of the colors field, or I was specifying it to be a string, and my colors method was returning a joined string of all the colors. Turns out acts_as_solr does the right thing if you just give it a Ruby array (though that doesn't seem to be documented anywhere).
And to perform the query:
>> results = Species.find_by_solr('rabbit', :facets => {
:zeros => false,
:fields => [:colors],
:query => [
'size:[0 TO 100]',
'size:[100 TO 500]',
'size:[500 TO 1000]'
]
})
>> results.facets
=> {"facet_fields"=>{"colors_facet"=>{""=>61, "red"=>5, "green"=>2, "blue"=>1, "yellow"=>1, "green"=>1, "orange"=>3, "pink"=>3, "magenta"=>1}}, "facet_dates"=>{}, "facet_queries"=>{"size_rf:[0 TO 100]"=>16, "size_rf:[100 TO 500]"=>34, "size_rf:[500 TO 1000]"=>17}}
]]>