开发者

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开发者_如何学Go 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜