Search code examples
ruby-on-railssunspotsunspot-rails

Rails Sunspot - Is it possible to retrieve a facet row by the value?


If I have a query facet (and therefore know the row's value), is it possible to retrieve a specific row from the facet based on the known value?

@search = Product.search do
  keywords(params[:q])

  facet(:price) do
    row "[* TO 25]" do
      with(:price, 0.0..25.0)
    end
    row "[25 TO 50]" do
      with(:price, 25.01..50.0)
    end
    row "[50 TO *]" do
      with(:price).greater_than(100.0)
    end
  end
end

And then in the view I'd do something like this:

row = @search.facet(:price).value('[25 TO 50]')

It would help in my formatting/prettying up my view output.

Is something like this possible?


Solution

  • The facet returns an array of rows, so you'd have to either select it from the array or map the array to a hash.