如果客户端搜索“铅笔”,则从结果中排除“铅笔刀”

时间:2013-06-24 19:04:23

标签: ruby-on-rails elasticsearch tire

我正在使用轮胎,我们面临搜索结果问题。 我们正在寻找铅笔'

  • '红铅笔'行
  • '电子卷笔刀'不行不应包含在结果集中。

这是模型上的轮胎设置:

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, analyzer: 'my_analyzer'
      indexes :short_description, boost: 10, analyzer: 'my_analyzer'

1 个答案:

答案 0 :(得分:0)

默认情况下,查询electronic pencil sharpener将被翻译为electronic OR pencil OR sharpener

如果您要排除包含sharpener的文档,请使用以下查询:electronic OR pencil NOT sharpener+electronic +pencil -sharpener

查看boolmatch查询以在Query DSL中表达这些条件; https://github.com/karmi/tire/tree/master/test/integration