我正嘗試使用Rails(3.2.8),Tire和ElasticSearch創建自定義映射。Rails /輪胎 - 防止屬性被索引
我想「標題」和「說明」是唯一的搜索/索引的屬性...但是,我似乎無法使這項工作:
下面是我的模型:
class BlogPost < ActiveRecord::Base
attr_accessible :title, :description, :attachment, :attachment_thumbnail
include Tire::Model::Search
include Tire::Model::Callbacks
tire.mapping do
indexes :id, :type => 'integer', :index => :not_analyzed, :include_in_all => false
indexes :attachment, :type => 'string', :index => :not_analyzed, :include_in_all => false
indexes :attachment_thumbnail, :type => 'string', :index => :not_analyzed, :include_in_all => false
indexes :title, analyzer: 'snowball', boost: 100
indexes :description, analyzer: 'snowball', boost: 100
end
def self.search(params)
tire.search(load: true, page: params[:page], per_page: 15) do
query do
boolean do
must { string params[:query], default_operator: "AND" } if params[:query].present?
end
end
end
end
end
如果你真的不希望字段被添加到索引中,爲什麼要添加它們呢? include_in_all選項用於使這些字段不可搜索,但可用於查詢過濾器。如果您在索引數據之後將該選項添加到映射字段中,則必須重新對數據進行索引以使其生效。否則舊的映射照原樣存在。 – 2014-12-16 08:24:28