[英]ruby on rails: ElasticSearch / Tire dynamic search on multiple indices
I've done a bunch of searching and I haven't been able to get an answer to this question - hopefully this isn't a repeat (apologies if it is)... 我已经做了很多搜索,但还没有得到这个问题的答案-希望这不是重复(如果可以的话,很抱歉)...
Preface: I'm using Rails & Tire to perform ElasticSearch. 前言:我正在使用Rails&Tire执行ElasticSearch。
I have an object, Place, with attributes "name", "city", "state", and "zip". 我有一个对象Place,具有属性“名称”,“城市”,“州”和“ zip”。 They are indexed as follows:
它们的索引如下:
indexes :name, :type => 'multi_field', :fields => {
:name => { :type => 'string', :analyzer => 'snowball' },
:"name.exact" => { :type => 'string', :index => :not_analyzed }
}
indexes :city
indexes :state
indexes :zip
There are three conditions for searching: 1. Name only, 2. (City, State OR Zip), 3. Name AND (City, State OR Zip). 有三个搜索条件:1.仅名称; 2.(城市,州或邮政编码); 3.名称与(城市,州或邮政编码)。
My code for the "query" block is: 我对“查询”块的代码是:
if (City, State).present?
boolean do
must { string "name:#{name}*" } if name.present?
must { string "city:#{city_state}*" }
must { string "state:#{city_state}*" }
end
elsif (Zip).present?
boolean do
must { string "name:#{name}*" } if name.present?
must { string "zip:#{query_parameters["zip"]}*" }
end
else
string "name:#{name}*" }
end
The aforementioned search conditions #1 and #2 work as expected against multiple tests. 前面提到的搜索条件#1和#2可以在多个测试中正常工作。 However, condition 3 does not - it seems to only pay attention to the "name" field.
但是,条件3并非如此-它似乎只注意“名称”字段。 I'm assuming it has something to do with using the "city_state" variable to search on both "city" and "state"... But I'm doing this because a user can enter either "Chicago" or "Illinois" in the City, State / Zip text box and the search should still work, using either the geographic center of Chicago or the geographic center of Illinois, respectively.
我假设它与使用“ city_state”变量搜索“ city”和“ state”有关……但是我这样做是因为用户可以在其中输入“ Chicago”或“ Illinois”分别使用芝加哥的地理中心或伊利诺伊州的地理中心的“城市”,“州/邮政编码”文本框和搜索应该仍然有效。
Anything obvious I'm doing wrong? 有什么明显的我做错了吗?
However, condition 3 does not - it seems to only pay attention to the "name" field
但是,条件3并非如此-它似乎只注意“名称”字段
Errr, isn't 嗯,不是
string "name:#{name}*"
telling it to do exactly that? 告诉它做到这一点?
or did you mean to just do 还是你只是想做
string "#{name}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.