【发布时间】:2015-04-26 03:44:37
【问题描述】:
我已经设置了太阳黑子,并且在我的 Place.name 字段中搜索得很好
现在我想通过“充当可标记”标签进行搜索
我已经为可标记类别设置了两个上下文
使用这个模型和控制器,我没有收到任何错误,但是当我搜索我的标签名称 sunspot 时没有返回任何结果。
我已经运行了rake sunspot:reindex 和rake sunspot:solr:reindex,但没有任何变化。
当我在 Rails 控制台中运行 Place.last.categories 时,我只得到一个数组 ["Category one","Category 2"]
型号
class Place < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged
searchable :auto_index => true, :auto_remove => true do
text :name, :stored => true
string :category_list, :multiple => true, :stored => true
end
acts_as_votable
acts_as_mappable :default_units => :kms,
:lat_column_name => :latitude,
:lng_column_name => :longitude
validates_presence_of :name , :state, :city, :neighborhood, :adress,:latitude, :longitude
belongs_to :user
acts_as_ordered_taggable_on :categories, :obstacles
end
控制器
class PlacesController < ApplicationController
before_action :set_place, only: [:show, :edit, :update, :destroy, :upvote, :downvote, :favorite]
before_action :authenticate_user!, except: [:index, :show]
# GET /places
# GET /places.json
def index
@search = Place.search do
fulltext params[:search]
end
@places = @search.results
end
【问题讨论】:
标签: ruby-on-rails acts-as-taggable-on sunspot-rails