【问题标题】:Problems to search ActsAsTaggableOn with sunspot使用太阳黑子搜索 ActsAsTaggableOn 的问题
【发布时间】:2015-04-26 03:44:37
【问题描述】:

我已经设置了太阳黑子,并且在我的 Place.name 字段中搜索得很好

现在我想通过“充当可标记”标签进行搜索

我已经为可标记类别设置了两个上下文

使用这个模型和控制器,我没有收到任何错误,但是当我搜索我的标签名称 sunspot 时没有返回任何结果。

我已经运行了rake sunspot:reindexrake 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


    【解决方案1】:

    在这种情况下你应该在你的标签模型中添加searchable块。在我的记忆中,标签模型可能有关联,如果你想了解更多关于如何索引Rails关联的信息,你可以查看this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-20
      • 2014-03-29
      • 1970-01-01
      • 1970-01-01
      • 2014-05-17
      相关资源
      最近更新 更多