首页 > 其他分享 >添加 拼音分词器 与 IK分词器 后的 映射结构与实体类(hotel)【ElasticSearch】

添加 拼音分词器 与 IK分词器 后的 映射结构与实体类(hotel)【ElasticSearch】

时间:2023-06-24 15:23:30浏览次数:46  
标签:实体类 String keyword hotel private analyzer 分词器 type

1、索引库

// 酒店数据索引库
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"
      }
    }
  }
}

2、实体类

package cn.itcast.hotel.pojo;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Data
@NoArgsConstructor
public class HotelDoc {
    private Long id;
    private String name;
    private String address;
    private Integer price;
    private Integer score;
    private String brand;
    private String city;
    private String starName;
    private String business;
    private String location;
    private String pic;
    private Object distance;
    private Boolean isAD;
    private List<String> suggestion;

    public HotelDoc(Hotel hotel) {
        this.id = hotel.getId();
        this.name = hotel.getName();
        this.address = hotel.getAddress();
        this.price = hotel.getPrice();
        this.score = hotel.getScore();
        this.brand = hotel.getBrand();
        this.city = hotel.getCity();
        this.starName = hotel.getStarName();
        this.business = hotel.getBusiness();
        this.location = hotel.getLatitude() + ", " + hotel.getLongitude();
        this.pic = hotel.getPic();
        // 组装suggestion
        if(this.business.contains("/")){
            // business有多个值,需要切割
            String[] arr = this.business.split("/");
            // 添加元素
            this.suggestion = new ArrayList<>();
            this.suggestion.add(this.brand);
            Collections.addAll(this.suggestion, arr);
        }else {
            this.suggestion = Arrays.asList(this.brand, this.business);
        }
    }
}

 

标签:实体类,String,keyword,hotel,private,analyzer,分词器,type
From: https://www.cnblogs.com/Rover20230226/p/17501144.html

相关文章

  • mmseg4j 中文分词器的一些简介整理
    在lucene中,我们是使用IndexWriter调用Analyzer将文章切成以词为单位的Stream,然后生成索引的。lucene内建的分词器很多,比如:按空白字符分词的WhitespaceAnalyzer,添加了stopword过滤的StopAnalyzer,以及最常用的是StandardAnalyzer。这些自带的分词器对中文支持多不好,我觉得比......
  • 学生管理系统实体类
      ......
  • Admin实体类
    publicclassAdmin{privateIntegeradminAccount;privateStringadminPassword;publicIntegergetAdminAccount(){returnadminAccount;}publicvoidsetAdminAccount(IntegeradminAccount){this.adminAccount=adminAccount;......
  • 学生管理系统实体类
     ......
  • jpa2.2.10 JpaSpecificationExecutor Specification 查询时,实体类中存在@OneToMany,怎
    对于这个问题,您可以在查询时通过join()方法指定不查询@OneToMany关联表。举个例子,如果有一个实体A与实体B是一对多关系,那么您可以这样写查询条件:@OneToMany(targetEntity=DcyRightImage.class,cascade={CascadeType.ALL},fetch=FetchType.EAGER)@JoinColumn(nam......
  • 实体类生成器
    publicclassPlusCodeGenerator{publicstaticvoidmain(String[]args){Stringauthor=scanner("请输入作者名称?");StringpkgName=scanner("请输入包名?");StringtableName=scanner("请输入表名,多个英文逗号分隔?");......
  • ES学习笔记--IK分词器
    IK分词器的安装:我这里是采用在线安装的方式:#进入容器内部dockerexec-itelasticsearch/bin/bash#在线下载并安装./bin/elasticsearch-plugininstallhttps://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.14.0/elasticsearch-anal......
  • 实体类中嵌套Enum类型并想转换成JSON字符串时遇到的问题。
    实体类中嵌套Enum类型并想转换成JSON字符串时遇到的问题。先说明问题的产生,在自己写着玩的时候,新建了一个User类如下:packagecom.ma.xdo;importlombok.*;importjava.io.Serializable;/***@ClassNameUser*@DescriptionTODO*@Author@O_o*@Date2023/6/814:......
  • java通过实体类生成数据库表 并生成注释
    java通过实体类生成数据库表并生成注释 方式一   使用A.C.Table A.C.Table是对Mybatis做的增强功能,实现了mybatis自动建表的能力官方地址:https://gitee.com/sunchenbin/mybatis-enhance文档地址:https://www.yuque.com/sunchenbin/actable/ag3y1y 项目结构 ......
  • asp.net core从数据库生成实体类,修改实体类
    前言花了我2个小时,终于知道怎么更新.netcore里面的模型层了。。。虽然方法很不正规提示:以下是本篇文章正文内容,下面案例可供参考一、asp.netcore生成从数据库生成实体类1、新建.netcore类库项目我是用的vs2019,其他版本类似2、安装NuGet程序包,三个如下图所示打开NuGet程序包选......