zoukankan      html  css  js  c++  java
  • ElasticSearch自定义分词器

    通过mapping中的映射,将&映射成and

    PUT /my_index?pretty' -H 'Content-Type: application/json' -d'
    {
        "settings": {
            "analysis": {
                "char_filter": {
                    "&_to_and": {
                        "type":       "mapping",
                        "mappings": [ "& => and "]
                }},
                "filter": {
                    "my_stopwords": {
                        "type":       "stop",
                        "stopwords": [ "the", "a" ]
                }},
                "analyzer": {
                    "my_analyzer": {
                        "type":         "custom",
                        "char_filter":  [ "html_strip", "&_to_and" ],
                        "tokenizer":    "standard",
                        "filter":       [ "lowercase", "my_stopwords" ]
                }}
    }}}
    '

    对于字符串"a & b" 输出的结果为a and b,感觉怪怪的,当前的应用常见没前还不清楚。先记录下这个功能吧。

    GET /my_index/_analyze?analyzer=my_analyzer&pretty' -H 'Content-Type: application/json' -d'
    a & b
    '

    另一种,可以通过正则表达是的方式,来匹配字符,如下,重新将com.test.abc分词成了com, test, abc

    PUT /my_index?pretty' -H 'Content-Type: application/json' -d'
    {
        "settings": {
            "analysis": {
                "char_filter": {
                    "dot": {
                        "type":       "pattern_replace",
                        "pattern":     "(\w+)\.(?=\w)",
                        "replacement": "$1 "
                    }
                },
                "analyzer": {
                    "my_analyzer": {
                        "char_filter":  ["dot"],
                        "tokenizer":    "whitespace"
                }}
    }}}
    '
  • 相关阅读:
    VUE.js入门学习(2)-基础精讲
    VUE中的MVVM模式
    VUE.js入门学习(1)-起步
    Vuex 是什么
    Proxy
    VUE常见的语法
    ES6的一些语法
    Element
    Mock.js
    第一阶段:Python开发基础 day14 三元表达式 生成器 匿名函数
  • 原文地址:https://www.cnblogs.com/woniu4/p/8259649.html
Copyright © 2011-2022 走看看