提高弹性搜索的相关价值

时间:2013-09-24 12:14:55

标签: ruby-on-rails elasticsearch

settings :analysis => {           
        :analyzer => {
          :my_analyzer => {
            "tokenizer"    => "lowercase",
           # "filter"       => ["synonym", "porterStem", "phonetic"]
            "filter"       => ["synonym", "porterStem"]
          }
        },
        :filter => {
          :synonym => {
              "type" => "synonym",
              "synonyms_path" => "#{Synonym.path}"
          }
        }
      } do
mapping do
  indexes :commodity_code
  indexes :commodity_name
  indexes :long_description, boost: 1,analyzer: 'my_analyzer'
  indexes :short_description, boost: 3, analyzer: 'my_analyzer'
  indexes :manufacturer_name
  indexes :manufacturer_part_number
  indexes :increase_relevance_text
  indexes :decrease_relevance_text     
end

配置ElasticSearch,使得如果最终用户提供的搜索词与Increase_Relevance_Text字段中的任何短语完全匹配,则该特定产品的相关性将增加Increase_Relevance_Points中的数量。

配置弹性搜索,以便如果最终用户提供的搜索词包含Decrease_Relevance_Text字段中包含的任何单词或短语(但不一定是完全匹配),则该特定产品的相关性会降低通过Decrease_Relevance_Points中的金额。

1 个答案:

答案 0 :(得分:0)

这是我得到的解决方案

应该

           custom_score :script => "_score+doc['increase_relevance_points'].value" do
            boolean do
             should { match :increase_relevance_text, term}
            end
           end
         end