2012-05-30 39 views
5

我繼承了一個通過輪胎進行一些彈性搜索的項目。忽略使用彈性搜索和輪胎的口音

該搜索正在工作,但通過它的重音。搜索「這個」需要返回「thís」和「thiš」。

我已閱讀本輪胎文檔:http://karmi.github.com/tire/

除了:http://railscasts.com/episodes/306-elasticsearch-part-1?view=asciicast

其中提到,大多數的彈性搜索的選項是在輪胎可用。

搜索關於忽略口音,asciifolding不斷涌現,但彈性搜索只是有這樣一段話吧:

http://www.elasticsearch.org/guide/reference/index-modules/analysis/asciifolding-tokenfilter.html

此外,我發現有關過濾器/口音/等諸如此類的幾件事情:

https://github.com/elasticsearch/elasticsearch/issues/890
https://gist.github.com/2142635

但他們都用裸彈性搜索選項。

當我嘗試在我的ruby代碼中使用asciifolding過濾器時,出現沒有爲「asciifolding」定義過濾器的錯誤。

下面是在我的代碼中進行的搜索的膽量 - 我該如何修改它以執行不區分重音的搜索。這是asciifolding,如果是這樣,我該如何在這裏申報?

result = tire.search(:load => true,page: params[:page], per_page: params[:per_page]) do 
    query { string "#{params[:term]}", :default_operator => 'and' } if params[:term].present? 
    filter :missing, :field => 'original_media_id' #see above 
    #asciifolding? 
    sort { by :updated_at, :desc } if params[:term].present? 
    facet 'files' do 
    terms 'indexed_files.file.id' 
    end 
end 

編輯:或者也許它應該在映射/索引?然後重新運行索引器。這裏的映射,我試過把:過濾器=>「asciifolding」的一些指標,但似乎並沒有工作(也不會產生任何錯誤輸出):

tire.mapping do 
    indexes :id, :index => :not_analyzed 
    indexes :name, :filter => "asciifolding" 
    indexes :description, :filter => "asciifolding" 
    indexes :created_at, :type => 'date' 
    indexes :updated_at, :type => 'date' 
    indexes :file_type 
    indexes :indexed_files, :type => 'object' do 
     indexes :file, :type => 'object', 
      :properties => { 
      :title => { 
      :type => "multi_field", 
       :fields => { 
       :raw => { :type => 'string', :index => 'not_analyzed'}, 
       :title => { :type => 'string', :filter => "asciifolding" } 
       } 
      }, 
      :description => { :type => "string", :filter => "asciifolding" } 
      } 
    end 
end 

回答

相關問題