alexs333
alexs333

Reputation: 12553

thinking_sphinx nested date search

Let's say I've got the following scenario:

class Conference < ActiveRecord::Base
    has_many :meetings

    define_index do
        # index
    end
end

class Meeting < ActiveRecord::Base
    belongs_to :conference

    validates_presence_of :start_time
    validates_presence_of :end_time
end

I would like to search conferences based on the start time, so when I provide the start time it would return me the list of conferences which still have one or more meetings with start times after the provided time. Is this possible with thinking_sphinx? At the very least, how should I define my index?

EDIT

The search needs to be for Conferences (i.e. Conference.seacch)

Upvotes: 0

Views: 45

Answers (1)

Sully
Sully

Reputation: 14943

class Meeting < ActiveRecord::Base
 belongs_to :conference

 ..
 define_index do
    indexes :start_time
    has conference_id
  end
end

Then

Meeting.search :conditions => {:created_at => 1.week.ago..Time.now}

http://freelancing-god.github.com/ts/en/indexing.html

http://freelancing-god.github.com/ts/en/searching.html

Upvotes: 1

Related Questions