2

I'm currently using rails 3.1, sphinx and thinking sphinx for my search app.

My model has two fields which I define as sphinx attributes:

define_index do

  has availability_period # number of days
  has availability_date
end

I want to search by this availability date so I'm using sphinx scope defined like this

# search by date e.g av_date = '01. Feb 2012'
# find items that are availabile for that date
sphinx_scope(:by_date){ |av_date|
  search_date = (Time.now-2.years)..av_date
  {
    :with => { :availability_date => search_date} 
  }  
}

However, item has availability_period in days, so I want actually to add number of this days to query.

So lets assume something like this:

item 1: {availability_date: '10. Jan 2012', availability_period: 14}
item 2: {availability_date: '10. Feb 2012', availability_period: 30}

Now I'm looking for items between '01. Jan 2011' - '30 Feb 2012'}, i want to find only item#1, and not item #2, because 10. Feb + 30 days gives 10 Mar, which is out of my range.

Johny
  • 1,441
  • 10
  • 26

0 Answers0