Thinking sphinx: query price> 0

Is a model of products with the indices

define_index do
indexes: name
indexes description
has product_shops.price,: as =>: price
has catalog_product_connections.catalog_id,: as =>: catalog_id
end

Need ability to filter by price.

The controller write this:

Product.search(’’, :with => {:price => params[:
price_from].to_i…params[:price_to].to_i})

It works.
But how to specify the query type: price > 1000?
I have tried this:

Product.search(’’, :with => [‘price>?’, params[: price_from]])

getting error
searchd error (status: 1): invalid or truncated request

What to do?

Sphinx doesn’t have the concept of greater or less than for filters -
not in a simple sense, anyway. The easiest approach is to have a range
between 1000 and a really big number (given it’s an integer, perhaps
2^32):

Product.search :with => {:price => 1000…(2**32)}

Give that a shot.


Pat

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs