Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7913757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:55:02+00:00 2026-06-03T13:55:02+00:00

Simple question, How do I search multiple models using Sunspot?…I’m using Sunspot with Rails,

  • 0

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?

Thanks for the help.

(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.)

I have the following in my view:

<div class="side_bar_search">
    <%= form_tag gears_path, :method => :get do %>
      <p>
        <%= text_field_tag :search, params[:search] %>
        <%= submit_tag "Search", :name => nil %>
    <% end %>
</div> 

and the following models

Gear

class Gear < 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 => :sub_category
  has_many :comments, :dependent => :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...

User

class User < 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 => :destroy 
  has_one :store, :dependent => :destroy
  before_save :create_remember_token
  require 'carrierwave/orm/activerecord'
  mount_uploader :userimage, UserpicUploader

   searchable do
     text :first_name, :last_name
   end...                    

Gears Controller

class GearsController < ApplicationController
  def index
    @search = Gear.search do
        fulltext params[:search]
        paginate(page: params[:page])
    end

    @gears = @search.results
  end...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:55:03+00:00Added an answer on June 3, 2026 at 1:55 pm
    Sunspot.search [Gear, User] do
      ....
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple question but I can't find the answer anywhere. No search strategy so far
Simple question: how can I resign my textfield if my done key is Search.
Normally, this is a trivial question that can be answered with a simple search
Simple question, but I can't quite seem to figure it out: If i have
This seems like a simple question, but I can't find it with the Stack
I want to add simple full-search-text to my webapp, that can accept multiple words
a simple question but I don't seem to have the right terminology to search
I have a simple question. How can I search NSMutable Dictionary? For eg. I
Really simple question - how do I do a search to find all records
This is a really simple question but I'm not sure how to search for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.