简体   繁体   English

Elasticsearch,轮胎和自动完成

[英]Elasticsearch, tire and autocomplete

Good day. 美好的一天。 I have elasticsearch in my rails app using tire. 我在使用轮胎的Rails应用程序中有elasticsearch。 I have many names in my db. 我的数据库中有很多名字。 And I want to search for them like search_query: "alex ivan", and the output should be ["Alexander Ivanov", "Alex Ivanenko] etc. (Real names from db) I tried to make it with this article but it's not searching. So I've made a quickhack: 我想搜索它们,例如search_query:“ alex ivan”,输出应为[“ Alexander Ivanov”,“ Alex Ivanenko]等。(数据库的实名)我试图通过本文实现,但并未进行搜索所以,我做了一个快速hack:

params[:search_query] = params[:search_query].split(" ").map{|a|a<<("*")}.join(" ") 

Is it a good decision or I can do it with analyzers etc. ? 这是一个好的决定,还是我可以使用分析仪等来做?

Here's what I did using analyzers for doing a search on names of businesses when I used ElasticSearch. 这是我使用ElasticSearch时使用分析器搜索企业名称的过程。 Place this inside your mapping block and modify the index appropriately -- I think this will give you what you want: 将其放在映射块内并适当地修改索引-我认为这将为您提供所需的内容:

indexes :name, :type => 'multi_field', :fields => {
  :name => { :type => 'string', :analyzer => 'standard' },
  :"name.exact" => { :type => 'string', :index => :not_analyzed }
}

Then inside your search and query blocks, something like: 然后在您的searchquery块中,类似于:

search do
  query do

    # either a must match for exact match
    boolean(:minimum_number_should_match => 1) do  
      must { string "name:#{<variable>}" }
    end

    # or a broader match
    string "name:#{<variable>}*"
  end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM