Reputation: 12558
I have problem with connecting conditional OR with filterint by date range. Something like that
#pseudo SQL syntax
(@date_start < params[:date_to_search] < @date_end) && (@every_day==1 || @day_of_week== params[:day])
--
class OfferTime < ActiveRecord::Base
define_index do
indexes every_day #boolean
indexes day_of_week #string eg. Tue, Mon etc
has date_start #Date NOT datetime
has date_end #Date
end
end
To make conditional OR I use this solution: Conditional "or" in Thinking Sphinx search
This works quite well.
(OfferTime.search "@every_day 1 | @day_of_week Tue", :match_mode => :extended).size
# => 2
# Correct answer
But I don't know how to connect that with that date range
(@date_start < params[:date_to_search] < @date_end)
Example:
(OfferTime.search "@every_day 1 | @day_of_week Tue & @date_start < #{1.year.ago}", :match_mode => :extended).size
# => 1
# wrong answer! should be 0!
Is it possible to make that with ThinkingSphinx?
Upvotes: 2
Views: 1230
Reputation: 16226
Not sure exactly the logic you're after - is it every day OR (day of week and date start)
, or (every day OR day of week) AND date start
?
The latter is possible - but you'll want to filter on the attribute using the :with arguments - it should be well-covered in the docs. To get a 'less than 1 year ago' filter, you'll need to use a range - from one year ago to today (or well into the future, if that's more appropriate).
If it's the former, I'm not sure if that's possible - but if it is, you'll likely need to investigate the expression syntax and Sphinx's select clause. Again, covered a bit in the TS docs, with links to the relevant Sphinx sections.
Upvotes: 0