1. 程式人生 > 其它 >修改拼音分詞器原始碼實現漢字/拼音/簡拼混合搜尋時同音字不匹配

修改拼音分詞器原始碼實現漢字/拼音/簡拼混合搜尋時同音字不匹配

拼音外掛下載(es版本6.5.4)

https://files.cnblogs.com/files/lcy2020/elasticsearch-analysis-pinyin-6.5.4.zip

配置參考

PUT /association_test/
{
  "settings": {
    "index": {
      "analysis": {
        "analyzer": {
          "pinyin_analyzer": {
            "tokenizer": "my_pinyin"
          }
        },
        "tokenizer": {
          "hp_pinyin": {
            "type": "pinyin",
            "keep_first_letter": true,
            "keep_separate_first_letter": true,
            "keep_full_pinyin": true,
            "keep_original": false,
            "limit_first_letter_length": 16,
            "keep_separate_chinese":true,
            "keep_none_chinese_in_first_letter":true,
            "lowercase": true
          }
        }
      }
    }
  },
  "mappings": {
    "route": {
      "properties": {
        "words": {
          "type": "completion",
          "fields": {
            "w-pinyin": {
              "type": "completion",
              "analyzer": "my_pinyin",
              "search_analyzer":"standard",
              "contexts": [
                { 
                  "name": "filter",
                  "type": "category",
                  "path": "filter"
                }
              ]
            }
          },
          "contexts": [
                { 
                  "name": "filter",
                  "type": "category",
                  "path": "filter"
                }
              ]
        }
      }
    }
  }
}

參考文章:
https://www.cnblogs.com/danvid/p/10691547.html
https://github.com/medcl/elasticsearch-analysis-pinyin