title: Searching Multiple Models Simultaneously in Sunspot/Solr for Rails
body: <p>Simple question, How do I search multiple models using Sunspot?...I'm using Sunspot with Rails, and I can't seem to find how I search across multiple models. Do I need to create a separate controller or can I use the Gear Controller with the index action?</p>
  
  <p>Thanks for the help.</p>
  
  <p>(side note: I found a question on stackoverflow very similar to this but they didn't post their code..so I apologize for any redundancy.)</p>
  
  <p>I have the following in my view:</p>
  
  <pre><code>&lt;div class="side_bar_search"&gt;
      &lt;%= form_tag gears_path, :method =&gt; :get do %&gt;
        &lt;p&gt;
          &lt;%= text_field_tag :search, params[:search] %&gt;
          &lt;%= submit_tag "Search", :name =&gt; nil %&gt;
      &lt;% end %&gt;
  &lt;/div&gt; 
  </code></pre>
  
  <p>and the following models</p>
  
  <p><strong>Gear</strong></p>
  
  <pre><code>class Gear &lt; ActiveRecord::Base
    attr_accessible :title, :size, :price, :sub_category_id, :user_id, :image, :image_a, :remote_image_url
    belongs_to :user
    belongs_to :sub_category
    has_one :category, :through =&gt; :sub_category
    has_many :comments, :dependent =&gt; :destroy 
    require 'carrierwave/orm/activerecord'
    mount_uploader :image, GearpicUploader
    mount_uploader :image_a, GearpicUploader
  
  
    searchable do
      text :title, :size, :price #need to add sub-category, and User Name.  
    end...
  </code></pre>
  
  <p><strong>User</strong></p>
  
  <pre><code>class User &lt; ActiveRecord::Base 
    attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :userimage, :remove_userimage
    has_secure_password
    has_many :gears
    has_many :comments, :dependent =&gt; :destroy 
    has_one :store, :dependent =&gt; :destroy
    before_save :create_remember_token
    require 'carrierwave/orm/activerecord'
    mount_uploader :userimage, UserpicUploader
  
     searchable do
       text :first_name, :last_name
     end...                    
  </code></pre>
  
  <p><strong>Gears Controller</strong></p>
  
  <pre><code>class GearsController &lt; ApplicationController
    def index
      @search = Gear.search do
          fulltext params[:search]
          paginate(page: params[:page])
      end
  
      @gears = @search.results
    end...
  </code></pre>