简体   繁体   English

Ruby on Rails:多个索引上的ElasticSearch / Tire动态搜索

[英]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.

相关问题 使用Tire和ElasticSearch搜索多个模型 - Search multiple models with Tire and ElasticSearch Ruby:ElasticSearch + Tire错误Tire :: Search :: SearchRequestFailed - IndexMissingException? - Ruby: ElasticSearch + Tire error Tire::Search::SearchRequestFailed - IndexMissingException? Ruby on Rails-ElasticSearch轮胎归因于现有数据库 - Ruby on rails -elasticsearch tire impoting existing db 属性相关的动态索引(轮胎,Rails)-ElasticSearch - Attribute dependent Dynamic Index (Tire, Rails) - ElasticSearch Ruby On Rails:ElasticSearch 身份验证(Tire 和 ElasticSearch-rails) - Ruby On Rails: ElasticSearch authentication (Tire and ElasticSearch-rails) 在ActiveRecord上进行Rails Tire搜索:多个字段之间的关系 - Rails Tire search on ActiveRecord:Relation on multiple fields 在Tire和Ruby on Rails上使用Elasticsearch搜索电子邮件时结果无效 - Invalid results when searching emails using elasticsearch with Tire and Ruby on Rails Ruby on Rails-Tire-elasticsearch,如何对要导入的数据进行排序? - Ruby on Rails - Tire - elasticsearch, how to sort data being imported? 包括有关在Elasticsearch on Rails(Gem Tire)上搜索的其他表格 - Include other table on Search of Elasticsearch on Rails (gem Tire) 通过has_many关联搜索Rails轮胎(ElasticSearch) - Rails tire(elasticsearch) search through has_many association
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM