[英]Tire/Elasticsearch Filtering on Attribute
因此,当客户登录到应用程序时,他们只能在自己的公司内进行搜索,因此我们试图过滤客户名称。 尽管日志输出似乎正确,但是没有返回搜索结果。
#report.rb
def self.search_for_client(params, client)
tire.search(load: true, page: params[:page], per_page: 20) do
query { string params[:q] } if params[:q].present?
filter :term, :client => client
end
end
#reports_controller.rb
def full_search
@query = params[:q]
if current_user.client.nil?
@results = Report.search params
else
@results = Report.search_for_client params, current_user.client.title
end
end
#log output
curl -X GET 'http://localhost:9200/reports/report/_search?load=true&size=20&pretty' -d '{"query":{"query_string":{"query":"thio"}},"filter":{"term":{"client":"ApplusRTD Norway"}},"size":20}'
实际上,主要问题是索引编制后我没有重启弹性搜索服务器。 我也调整了search_for_client方法。
#report.rb
def self.search_for_client(params, client)
tire.search(load: true, page: params[:page], per_page: 20) do
query do
boolean do
must { string params[:q], default_operator: "AND" } if params[:q].present?
must { string 'status:active' }
end
end
filter :term, :client => [client]
end
结束
#output
curl -X GET 'http://localhost:9200/reports/report/_search?size=20&pretty' -d '{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "UT-12-541"
}
}
]
}
},
"filter": {
"term": {
"client": [
"Fabricom GDF Suez"
]
}
},
"size": 20
}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.