【问题标题】:Using Shingles and Stop words with Elasticsearch and Lucene 4.4在 Elasticsearch 和 Lucene 4.4 中使用带状疱疹和停用词
【发布时间】:2015-02-09 04:38:18
【问题描述】:

在我正在构建的索引中,我有兴趣运行一个查询,然后(使用构面)返回该查询的 shingles。这是我在文本中使用的分析器:

{
  "settings": {
    "analysis": {
      "analyzer": {
        "shingleAnalyzer": {
          "tokenizer": "standard",
          "filter": [
            "standard",
            "lowercase",
            "custom_stop",
            "custom_shingle",
            "custom_stemmer"
          ]
        }
      },
      "filter": {
        "custom_stemmer" : {
            "type": "stemmer",
            "name": "english"
        },
        "custom_stop": {
            "type": "stop",
            "stopwords": "_english_"
        },
        "custom_shingle": {
            "type": "shingle",
            "min_shingle_size": "2",
            "max_shingle_size": "3"
        }
      }
    }
  }
}

主要问题是,在 Lucene 4.4 中,停止过滤器不再支持 enable_position_increments 参数来消除包含停止词的带状疱疹。相反,我会得到类似的结果..

“红黄相间”

"terms": [
    {
        "term": "red",
        "count": 43
    },
    {
        "term": "red _",
        "count": 43
    },
    {
        "term": "red _ yellow",
        "count": 43
    },
    {
        "term": "_ yellow",
        "count": 42
    },
    {
        "term": "yellow",
        "count": 42
    }
]

这自然会极大地扭曲返回的带状疱疹数量。 Lucene 4.4 后有没有办法在不对结果进行后处理的情况下管理这个问题?

【问题讨论】:

标签: elasticsearch lucene stop-words


【解决方案1】:

可能不是最优化的解决方案,但最直接的方法是在分析器中添加另一个过滤器以杀死“_”填充标记。在下面的示例中,我将其称为“kill_fillers”:

   "shingleAnalyzer": {
      "tokenizer": "standard",
      "filter": [
        "standard",
        "lowercase",
        "custom_stop",
        "custom_shingle",
        "custom_stemmer",
        "kill_fillers"
       ],
       ...

将“kill_fillers”过滤器添加到您的过滤器列表中:

"filters":{
...
  "kill_fillers": {
    "type": "pattern_replace",
    "pattern": ".*_.*",
    "replace": "",
  },
...
}

【讨论】:

    【解决方案2】:

    我不确定这是否有帮助,但在带状疱疹的弹性定义中,您可以使用参数filler_token,默认情况下为_。例如,将其设置为空字符串:

    $indexParams['body']['settings']['analysis']['filter']['shingle-filter']['filler_token'] = "";
    

    https://www.elastic.co/guide/en/elasticsearch/reference/1.7/analysis-shingle-tokenfilter.html

    【讨论】:

      猜你喜欢
      • 2017-07-13
      • 1970-01-01
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多