Sunspot solr search on multiple fields of associated models

I have a 2 entities which have many to many relation say teacher and
subject. Each teacher has many subjects. I want to perform search on
teacher by sunspot solr for all the teacher who teaches 3 subjects
biology,
anatomy and botany with specific time.


Say model structures and relations as follows

Teacher - name, roll, ph no
has many :subjects
searchable do
  string :subjects, multiple => true, stored => true do
   subjects.map(&:title)
  end
  string :time, multiple => true, stored => true do
    subjects.map(&:time)
  end
end

Subject - title, time, teacher_id
belongs_to :teacher

How would I perform solr search query for the teachers who are having
all 3
subjects biology, anatomy and botany at time 3:00pm.
I am trying with following code which is not taking and condition to
retrieve only the teachers teaching all the 3 subjects rather its taking
as
or condition.

Sunspot.search(Teacher) do
  with(:subjects, "biology")
  with(:subjects, "anatomy")
  with(:subjects, "botany")
  with(:time, "3:00pm")
end.results

Hi,

Just go through the below link.

https://github.com/sunspot/sunspot

Thanks,
Prakash.N

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs