私は国のリストを持っており、ユーザーが結果を国別にソートできるようにしたいと考えています。だから私はこのヘルパーを持っています:
def facets_for model, field
ul = ""
links = ""
model.facets[field]['terms'].each do |facet|
links << content_tag('li') do
link_to("#{facet['term']} #{facet['count']}", params.merge(field => facet['term']))
end
end
ul << content_tag("ul", class: field) do
links.html_safe
end
ul.html_safe
終わり
そしてモデルでは:
class model
....
mapping do
indexes :country do
indexes :name, :type => :string, index: "not_analyzed"
end
end
def self.search params
...
filter :term, destination: params[:destination] if params[:destination].present?
facet("destination") { terms 'country.name' }
...
end
しかし
ファセット['期間']
国名を常に小文字で返します。Country.find(facet).name で作れますが、不要だと思います。フィールドと同じ文字列値をファセットに格納する方法はありますか?
更新しました
私のマッピング:
{
"wishes" : {
"wish" : {
"properties" : {
"body" : {
"type" : "string"
},
"country" : {
"properties" : {
"name" : {
"type" : "string"
}
}
},
"country_id" : {
"type" : "string"
},
"created_at" : {
"type" : "date",
"format" : "dateOptionalTime"
}
} ... }}}