简单的问题,如何使用 Sunspot 搜索多个模型?...我正在使用带有 Rails 的 Sunspot,但我似乎无法找到如何搜索多个模型。我需要创建一个单独的控制器还是可以将齿轮控制器与索引操作一起使用?
谢谢您的帮助。
(旁注:我在stackoverflow上发现了一个与此非常相似的问题,但他们没有发布他们的代码......所以我为任何冗余道歉。)
在我看来,我有以下几点:
<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>
以及以下型号
齿轮
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...
用户
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...
齿轮控制器
class GearsController < ApplicationController
def index
@search = Gear.search do
fulltext params[:search]
paginate(page: params[:page])
end
@gears = @search.results
end...