Question

I am using Sunspot gem to search products, stores, styles, and prices

I am able to search and and use my filters to modify searches.

I have price range slider in the filter pane. How can use this slider to search a price range for products?

The slider has a input for low/high values

      <div class="collapse_content panel-collapse collapse in" id="price_content">
        <div class="panel-body">
          <div id="slide_wrapper">
            <div id="slider-range"></div>
            <input type="text" id="low_end">
            <input type="text" id="high_end">
          </div>
        </div>
      </div>

Frankly, maybe I'm just tired but I'm not even sure where to start from a sunspot sold perspective.

Any help would be appreciated.

Was it helpful?

Solution

You can use between which accepts a range of numbers:

Sunspot.search(MyModel) do
  with(:price).between(low_price..high_price)
end

If you only want to search for a minimum or maximum price, instead of between you can use greater_than_or_equal_to or less_than_or_equal_to respectively, which both accept a number:

Sunspot.search(MyModel) do
  with(:price).greater_than_or_equal_to(low_price)
end

See the Sunspot Wiki for more options.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top