How to search data on created at less than in thinking sphinx

102 Views Asked by At

Using thinking_sphinx to fetch data from records. It working fine but facing an issue that not find any to get records on date comparison like created_at greater than or less than. I check their official documentation also Thinking Sphinx

Is thinking sphinx provide that way? If yes then can we do that

1

There are 1 best solutions below

0
pat On BEST ANSWER

It is possible, but it's not entirely obvious.

What you'll need to do is add an extra column in the SELECT clause, and then filter by that. Something along the lines of:

Model.search "pancakes",
  :select => "*, IF(created_at > #{1.year.ago.to_i}, 1, 0) AS time_match",
  :with   => {:time_match => 1}

You will need to have created_at as an attribute in your index file for this to work.