当前位置: 首页> 文旅> 艺术 > 好的微商城平台_建筑行业征信查询平台_营销型企业网站有哪些平台_2021年度关键词有哪些

好的微商城平台_建筑行业征信查询平台_营销型企业网站有哪些平台_2021年度关键词有哪些

时间:2025/7/10 20:53:37来源:https://blog.csdn.net/dengfengling999/article/details/146764625 浏览次数:0次
好的微商城平台_建筑行业征信查询平台_营销型企业网站有哪些平台_2021年度关键词有哪些

#测试拼音分词
POST /_analyze
{
  "text":"如家酒店真不错",
  "analyzer": "pinyin"
}
#这里把拼音的首字母放到这里,也说明了这句话没有被分词,而是作为一个整体出现的
#还把每一个字都形成了一个拼音,这也没什么用 大多数情况下我们想用中文搜索

#自定义分词器  创建test索引库的时候指定字段使用自定义的分词
PUT /test
{
  "settings": {
    "analysis": {
      "analyzer": {
          "my_analyzer":{
          "tokenizer":"ik_max_word",
          "filter":"py"
        } 
      },
      "filter":{
        "py":{
          "type":"pinyin",
          "keep_full_pinyin":false,
          "keep_joined_full_pinyin":true,
          "keep_original":true,
          "limit_first_letter_length":16,
          "remove_duplicated_term":true,
          "none_chinese_pinyin_tokenize":false
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "name":{
        "type": "text",
        "analyzer": "my_analyzer"
      }
    }
  }
}

#删除索引库
DELETE /test

#查询索引库
GET /test


#在分词分词的汉字拼音都有,而且还有分词的首字母拼音
POST /test/_analyze
{
  "text":["如家酒店真不错"],
  "analyzer": "my_analyzer"
}

#在索引库test中插入一些文档
POST /test/_doc/1
{
  "id":1,
  "name":"狮子"
}

POST /test/_doc/2
{
  "id":2,
  "name":"虱子"
}

#搜索:有点问题搜索拼音,把同音字也搜到了
GET /test/_search
{
  "query": {
    "match": {
      "name": "shizi"
    }
  }
}

#在创建的时候可以用拼音选择器,在搜索的时候不应该用拼音选择器,搜索用search_analyzer,在搜索是用户输入的是中文,用户用中文去搜,输入的是拼音,才拿拼音去搜

#自定义分词器  创建test索引库的时候指定字段使用自定义的分词
PUT /test
{
  "settings": {
    "analysis": {
      "analyzer": {
          "my_analyzer":{
          "tokenizer":"ik_max_word",
          "filter":"py"
        } 
      },
      "filter":{
        "py":{
          "type":"pinyin",
          "keep_full_pinyin":false,
          "keep_joined_full_pinyin":true,
          "keep_original":true,
          "limit_first_letter_length":16,
          "remove_duplicated_term":true,
          "none_chinese_pinyin_tokenize":false
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "name":{
        "type": "text",
        "analyzer": "my_analyzer",
        "search_analyzer": "ik_smart"
      }
    }
  }
}
#现在搜索是用户输入的是中文,用户用中文去搜,输入的是拼音,才拿拼音去搜
GET /test/_search
{
  "query": {
    "match": {
      "name": "虱子"
    }
  }
}


#自动补全  参与自动补全的的字段必须是completion类型,字段的内容一般是用来补全的多个词条形成的数组
#创建索引库
PUT /test2
{
  "mappings": {
    "properties": {
      "title":{
        "type": "completion"
      }
    }
  }
}

#查询索引库
GET /test2

#删除索引库
DELETE /test2

#插入数据
POST test2/_doc
{
  "title":["Sorry","WH-1000XM3"]
}

POST test2/_doc
{
  "title":["SK-IT","PITERA"]
}

POST test2/_doc
{
  "title":["Nintendo","switch"]
}

#自动补全查询
GET /test2/_search
{
  "suggest":{
    "titleSuggest":{
      "text":"s",
      "completion":{
        "field":"title",
        "skip_duplicates":true,
        "size":10
      }
    }
  }
}

GET /test2/_search
{
  "suggest":{
    "titleSuggest":{
      "text":"so",
      "completion":{
        "field":"title",
        "skip_duplicates":true,
        "size":10
      }
    }
  }
}

#查看索引库的结构
GET /hotel/_mapping

#删除索引库
DELETE /hotel

#酒店数据索引库
#定义了两个分词器,全文检索用text_anlyzer,自动补全用completion_analyzer
PUT /hotel
{
  "settings": {
    "analysis": {
      "analyzer": {
        "text_anlyzer": {
          "tokenizer": "ik_max_word",
          "filter": "py"
        },
        "completion_analyzer": {
          "tokenizer": "keyword",
          "filter": "py"
        }
      },
      "filter": {
        "py": {
          "type": "pinyin",
          "keep_full_pinyin": false,
          "keep_joined_full_pinyin": true,
          "keep_original": true,
          "limit_first_letter_length": 16,
          "remove_duplicated_term": true,
          "none_chinese_pinyin_tokenize": false
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "id":{
        "type": "keyword"
      },
      "name":{
        "type": "text",
        "analyzer": "text_anlyzer",
        "search_analyzer": "ik_smart",
        "copy_to": "all"
      },
      "address":{
        "type": "keyword",
        "index": false
      },
      "price":{
        "type": "integer"
      },
      "score":{
        "type": "integer"
      },
      "brand":{
        "type": "keyword",
        "copy_to": "all"
      },
      "city":{
        "type": "keyword"
      },
      "starName":{
        "type": "keyword"
      },
      "business":{
        "type": "keyword",
        "copy_to": "all"
      },
      "location":{
        "type": "geo_point"
      },
      "pic":{
        "type": "keyword",
        "index": false
      },
      "all":{
        "type": "text",
        "analyzer": "text_anlyzer",
        "search_analyzer": "ik_smart"
      },
      "suggestion":{
          "type": "completion",
          "analyzer": "completion_analyzer"
      }
    }
  }
}

#查询所有
GET /hotel/_search
{
  "query":{
    "match_all": {}
  }
}

#自动补全查询
GET /hotel/_search
{
  "suggest":{
    "suggestions":{
      "text":"h",
      "completion":{
        "field":"suggestion",
        "skip_duplicates":true,
        "size":10
      }
    }
  }
}

 //自动补全查询:@Testvoid testSuggest() throws IOException {//准备requuestSearchRequest request=new SearchRequest("hotel");//准备DSLrequest.source().suggest(new SuggestBuilder().addSuggestion("suggestions",SuggestBuilders.completionSuggestion("suggestion").prefix("hz").skipDuplicates(true).size(10)));//发起请求SearchResponse response = client.search(request, RequestOptions.DEFAULT);//解析结果System.out.println(response);Suggest suggest = response.getSuggest();//根据补全查询名称,获取补全结果CompletionSuggestion suggestions= suggest.getSuggestion("suggestions");//获取optionsList<CompletionSuggestion.Entry.Option> options = suggestions.getOptions();//遍历for (CompletionSuggestion.Entry.Option option:options){String text = option.getText().toString();System.out.println(text);}}

@Overridepublic List<String> getSuggestions(String prefix) {//准备requuestSearchRequest request=new SearchRequest("hotel");//准备DSLrequest.source().suggest(new SuggestBuilder().addSuggestion("suggestions",SuggestBuilders.completionSuggestion("suggestion").prefix(prefix).skipDuplicates(true).size(10)));try {//发起请求SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);//解析结果System.out.println(response);Suggest suggest = response.getSuggest();//根据补全查询名称,获取补全结果CompletionSuggestion suggestions= suggest.getSuggestion("suggestions");//获取optionsList<CompletionSuggestion.Entry.Option> options = suggestions.getOptions();//遍历List<String> list=new ArrayList<>(options.size());for (CompletionSuggestion.Entry.Option option:options){String text = option.getText().toString();System.out.println(text);list.add(text);}return list;} catch (IOException e) {throw new RuntimeException(e);}}

关键字:好的微商城平台_建筑行业征信查询平台_营销型企业网站有哪些平台_2021年度关键词有哪些

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: