bob*_*eno 2 search ruby-on-rails elasticsearch tire
使用Elasticsearch与Rails 3和轮胎宝石.
我有一些方面可以在几个领域工作,但我现在有一个特殊的要求,并不确定它是否可行.我的模型Project上有两个字段,它们都存储相同的值:Country1和Country2
允许用户为项目存储最多两个国家/地区.两者的下拉菜单都是相同的.这两个领域都不需要.
我想要的是一个单独的方面,它"合并"来自Country1和Country2的值,并且可以智能地处理这些方面的点击(即无论是1还是2都会找到它)
这是我到目前为止的模型:(注意Country1/2可以是多个单词)
class Project < ActiveRecord::Base
mapping do
indexes :id
indexes :title, :boost => 100
indexes :subtitle
indexes :country1, :type => 'string', :index => 'not_analyzed'
indexes :country2, :type => 'string', :index => 'not_analyzed'
end
def self.search(params)
tire.search(load: true, page: params[:page], per_page: 10) do
query do
boolean do
must { string params[:query], default_operator: "AND" } if params[:query].present?
must { term :country1, params[:country] } if params[:country].present?
end
end
sort { by :display_type, "desc" }
facet "country" do
terms :country1
end
end
end
Run Code Online (Sandbox Code Playgroud)
任何提示非常感谢!
Tire中的这个提交https://github.com/karmi/tire/commit/730813f支持聚合"条款"方面的多个字段.
界面是:
Tire.search('articles-test') do
query { string 'foo' }
# Pass fields as an array, not string
facet('multi') { terms ['bar', 'baz'] }
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2200 次 |
| 最近记录: |