我試圖索引一個模型,當我有一個has_many, :through
關聯,但沒有結果顯示。Rails:Elasticsearch:通過關聯映射
class Business < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
def self.search(params)
tire.search(load: true) do
query { string params[:q]} if params[:q].present?
end
end
mapping do
indexes :service_name
indexes :service_description
indexes :latitude
indexes :longitude
indexes :services do
indexes :service
indexes :description
end
end
def to_indexed_json #returns json data that should index (the model that should be searched)
to_json(methods: [:service_name, :service_description], include: { services: [:service, :description]})
end
def service_name
services.map(&:service)
end
def service_description
services.map(&:description)
end
has_many :professionals
has_many :services, :through => :professionals
end
然後,這是服務模式
class Service < ActiveRecord::Base
attr_accessible :service, :user_id, :description
belongs_to :professional
belongs_to :servicable, polymorphic: true
end
我用這個也重新索引:
rake environment tire:import CLASS=Business FORCE=true
我可以搜索業務的項目,但是當我試圖尋找的東西在服務中,我得到一個空的結果。
這種方法仍然不適用於我。我仍然獲得零輸出 – hellomello
您是否重新編制了模型索引?如果是這樣,請嘗試使用Sense chrome擴展來瀏覽您創建的索引,以查看您是否在新列中有任何數據。 – Houen
我做了重新索引模型,並檢查了感覺,它只是給了我空陣列。我不確定它是否正在從'services'獲得模型 – hellomello