Note that there are some explanatory texts on larger screens.

plurals
  1. POSearching across multiple models using sunspot/solr
    text
    copied!<p>I have been able to implement a basic full text search successfully, however any queries involving models from many to many relations don't seem to work for me when i try to use scopes ("with statements"). I know the relevant rows are in the db as my sql statements do return the data. however the sunspot queries don't return any results…i'm sure its probably a newbie goof up on my end…any assistance would be greatly appreciated…so here we go….</p> <h2>My Models</h2> <pre><code>class User has_one :registration searchable do text :first_name text :last_name text :email end end class Registration belongs_to :user has_many :registration_programs has_many :programs, :through =&gt; :registration_programs searchable do integer :user_id integer :registration_status_id end end class RegistrationProgram belongs_to :registration belongs :program searchable do integer :registration_id integer :program_id end end </code></pre> <h2>My Query in the Controller</h2> <pre><code> @search = Sunspot.search(User, Registration, RegistrationPrograms)do # this works fine with the frame, lame, email fields "on its own" fulltext params["instructor-search"] any_of all_of with(:class =&gt; Registraion) with(:registration_status_id, 3) end all_of with(:class =&gt; RegistraionProgram) with(:program_id, 1) end end end </code></pre> <p>There are records in the database that have foo as f_name and 3 and 1 ids for their reg status and program fields. however i can't get Sunspot/websolr to get them….the only time i have had the above query to work is when i run all the three criteria "individually"….! Whenever I combine them i don't seem to get any rows returned. </p> <p>Any help/suggestions would be greatly appreciated…….</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload