I have a 2 entities which have many to many relation say teacher and
slot. Each teacher has many classes he/she takes up and each class is a
slot. I want to perform search on teacher by sunspot solr for all the
teacher who takes classes for different days in specific time.
Say model structures and relations as follows
class Teacher < ActiveRecord::Base
attr_accessible - name, address, phone
has many :slots
searchable do
string :day, multiple => true, stored => true do
slots.map(&:day)
end
string :start_time, multiple => true, stored => true do
slots.map(&:start_time)
end
string :start_time, multiple => true, stored => true do
slots.map(&:end_time)
end
end
end
class Slot < ActiveRecord::Base
attr_accessible - day, start_time, end_time teacher_id
belongs_to :teacher
end
The possible values for day attribute is slot are "Sunday",
"Monday",
"Tuesday", etc
and start and end time would be "2:00pm", "6:00pm", etc in
the database
How would I perform solr search query for the teachers who are having
for 3 days Monday, Tuesday and Wednesday between the time "2:00pm" and
"5:00pm"
I am trying with following code which is not taking "AND" condition to
retrieve only the teachers having classes all 3 days rather taking as
"OR" condition.
Sunspot.search(Teacher) do
with(:day, "Monday")
with(:day, "Tuesday")
with(:day, "Wednesday")
with(:start_time).greater_than_or_equal_to("2:00pm")
with(:end_time).less_than_or_equal_to("5:00pm")
end.results
I am using solr version 3.5 and sunspot_rails (2.0.0) and sunspot_solr
(2.0.0) gems for solr in rails and my rails version is 3.2.6
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/9066e08c549ac8538579d20e624ad935%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.