0

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)

alexs333
  • 12,143
  • 11
  • 51
  • 89

1 Answers1

1
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

Sully
  • 14,672
  • 5
  • 54
  • 79
  • That makes sense, but in this case we are searching meetings, not conferences. Would it be possible to implemented with the search on the Conference model? – alexs333 Jul 13 '12 at 05:06
  • How are you going to search for meeting start time starting from the conference? You will just re-route which will search in the meetings table. "Meeting.* where conference_id=x" The column you want to search for needs to exist in the model you want to use .search with – Sully Jul 13 '12 at 06:17
  • I guess that's the case. After all, moving indexing to the Metting model works. – alexs333 Jul 17 '12 at 23:32