mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-07 01:28:37 +08:00
v0.9.50
1.调整注解名称 2.修复1处geoShape不能通过shapeId检索的缺陷
This commit is contained in:
parent
72684f98c3
commit
dd356c322a
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<artifactId>easy-es-parent</artifactId>
|
||||
<version>0.9.40</version>
|
||||
<version>0.9.50</version>
|
||||
<relativePath>../easy-es-parent</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ import java.lang.annotation.Target;
|
||||
**/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.FIELD, ElementType.ANNOTATION_TYPE})
|
||||
public @interface TableField {
|
||||
public @interface IndexField {
|
||||
/**
|
||||
* 自定义字段在es中的名称
|
||||
*
|
||||
@ -14,7 +14,7 @@ import java.lang.annotation.Target;
|
||||
**/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface TableId {
|
||||
public @interface IndexId {
|
||||
/**
|
||||
* 字段值
|
||||
*
|
||||
@ -16,7 +16,7 @@ import java.lang.annotation.Target;
|
||||
**/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
|
||||
public @interface TableName {
|
||||
public @interface IndexName {
|
||||
/**
|
||||
* 实体对应的索引名
|
||||
*
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easy-es-parent</artifactId>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<version>0.9.40</version>
|
||||
<version>0.9.50</version>
|
||||
<relativePath>../easy-es-parent</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<artifactId>easy-es-parent</artifactId>
|
||||
<version>0.9.40</version>
|
||||
<version>0.9.50</version>
|
||||
<relativePath>../easy-es-parent</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<artifactId>easy-es-parent</artifactId>
|
||||
<version>0.9.40</version>
|
||||
<version>0.9.50</version>
|
||||
<relativePath>../easy-es-parent</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cn.easyes.core.biz;
|
||||
|
||||
import cn.easyes.annotation.TableField;
|
||||
import cn.easyes.annotation.IndexField;
|
||||
import cn.easyes.common.enums.FieldStrategy;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
import cn.easyes.core.config.GlobalConfig;
|
||||
@ -85,7 +85,7 @@ public class EntityFieldInfo {
|
||||
* @param field 字段
|
||||
* @param tableField 字段注解
|
||||
*/
|
||||
public EntityFieldInfo(GlobalConfig.DbConfig dbConfig, Field field, TableField tableField) {
|
||||
public EntityFieldInfo(GlobalConfig.DbConfig dbConfig, Field field, IndexField tableField) {
|
||||
this.column = field.getName();
|
||||
|
||||
// 优先使用单个字段注解,否则使用全局配置
|
||||
|
||||
@ -305,7 +305,14 @@ public class WrapperProcessor {
|
||||
return null;
|
||||
}
|
||||
|
||||
GeoShapeQueryBuilder builder = QueryBuilders.geoShapeQuery(geoParam.getField(), geoParam.getGeometry());
|
||||
// 构造查询参数
|
||||
GeoShapeQueryBuilder builder;
|
||||
if (StringUtils.isNotBlank(geoParam.getIndexedShapeId())) {
|
||||
builder = QueryBuilders.geoShapeQuery(geoParam.getField(), geoParam.getIndexedShapeId());
|
||||
} else {
|
||||
builder = QueryBuilders.geoShapeQuery(geoParam.getField(), geoParam.getGeometry());
|
||||
}
|
||||
|
||||
Optional.ofNullable(geoParam.getShapeRelation()).ifPresent(builder::relation);
|
||||
Optional.ofNullable(geoParam.getBoost()).ifPresent(builder::boost);
|
||||
return builder;
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package cn.easyes.core.toolkit;
|
||||
|
||||
import cn.easyes.annotation.HighLight;
|
||||
import cn.easyes.annotation.TableField;
|
||||
import cn.easyes.annotation.TableId;
|
||||
import cn.easyes.annotation.TableName;
|
||||
import cn.easyes.annotation.IndexField;
|
||||
import cn.easyes.annotation.IndexId;
|
||||
import cn.easyes.annotation.IndexName;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
import cn.easyes.common.enums.IdType;
|
||||
import cn.easyes.common.params.DefaultNestedClass;
|
||||
@ -21,7 +21,6 @@ import com.alibaba.fastjson.parser.deserializer.ExtraProcessor;
|
||||
import com.alibaba.fastjson.serializer.NameFilter;
|
||||
import com.alibaba.fastjson.serializer.SerializeFilter;
|
||||
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
@ -256,7 +255,7 @@ public class EntityInfoHelper {
|
||||
boolean hasAnnotation = false;
|
||||
|
||||
// 初始化封装TableField注解信息
|
||||
if (field.isAnnotationPresent(TableField.class)) {
|
||||
if (field.isAnnotationPresent(IndexField.class)) {
|
||||
initTableFieldAnnotation(dbConfig, entityInfo, field, fieldList);
|
||||
hasAnnotation = true;
|
||||
}
|
||||
@ -281,7 +280,7 @@ public class EntityInfoHelper {
|
||||
*/
|
||||
private static void initTableFieldAnnotation(GlobalConfig.DbConfig dbConfig, EntityInfo entityInfo,
|
||||
Field field, List<EntityFieldInfo> fieldList) {
|
||||
TableField tableField = field.getAnnotation(TableField.class);
|
||||
IndexField tableField = field.getAnnotation(IndexField.class);
|
||||
if (tableField.exist()) {
|
||||
// 存在字段处理
|
||||
EntityFieldInfo entityFieldInfo = new EntityFieldInfo(dbConfig, field, tableField);
|
||||
@ -381,7 +380,7 @@ public class EntityInfoHelper {
|
||||
allFields.forEach(field -> {
|
||||
String mappingColumn;
|
||||
// 处理TableField注解
|
||||
TableField tableField = field.getAnnotation(TableField.class);
|
||||
IndexField tableField = field.getAnnotation(IndexField.class);
|
||||
if (Objects.isNull(tableField)) {
|
||||
mappingColumn = getMappingColumn(dbConfig, field);
|
||||
EntityFieldInfo entityFieldInfo = new EntityFieldInfo(dbConfig, field);
|
||||
@ -464,7 +463,7 @@ public class EntityInfoHelper {
|
||||
*/
|
||||
private static boolean initTableIdWithAnnotation(GlobalConfig.DbConfig dbConfig, EntityInfo entityInfo,
|
||||
Field field) {
|
||||
TableId tableId = field.getAnnotation(TableId.class);
|
||||
IndexId tableId = field.getAnnotation(IndexId.class);
|
||||
if (tableId != null) {
|
||||
// 主键策略( 注解 > 全局 )
|
||||
// 设置 Sequence 其他策略无效
|
||||
@ -523,7 +522,7 @@ public class EntityInfoHelper {
|
||||
*/
|
||||
public static boolean isExistTableId(List<Field> list) {
|
||||
for (Field field : list) {
|
||||
TableId tableId = field.getAnnotation(TableId.class);
|
||||
IndexId tableId = field.getAnnotation(IndexId.class);
|
||||
if (tableId != null) {
|
||||
return true;
|
||||
}
|
||||
@ -552,7 +551,7 @@ public class EntityInfoHelper {
|
||||
private static void initTableName(Class<?> clazz, GlobalConfig globalConfig, EntityInfo entityInfo) {
|
||||
// 数据库全局配置
|
||||
GlobalConfig.DbConfig dbConfig = globalConfig.getDbConfig();
|
||||
TableName table = clazz.getAnnotation(TableName.class);
|
||||
IndexName table = clazz.getAnnotation(IndexName.class);
|
||||
String tableName = clazz.getSimpleName().toLowerCase(Locale.ROOT);
|
||||
String tablePrefix = dbConfig.getTablePrefix();
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<artifactId>easy-es-parent</artifactId>
|
||||
<version>0.9.40</version>
|
||||
<version>0.9.50</version>
|
||||
<relativePath>../easy-es-parent</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<artifactId>easy-es-parent</artifactId>
|
||||
<version>0.9.40</version>
|
||||
<version>0.9.50</version>
|
||||
|
||||
<name>easy-es-parent</name>
|
||||
<description>easy use for elastic search</description>
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<artifactId>easy-es</artifactId>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<version>0.9.40</version>
|
||||
<version>0.9.50</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package cn.easyes.sample.entity;
|
||||
|
||||
import cn.easyes.annotation.HighLight;
|
||||
import cn.easyes.annotation.TableField;
|
||||
import cn.easyes.annotation.TableId;
|
||||
import cn.easyes.annotation.TableName;
|
||||
import cn.easyes.annotation.IndexField;
|
||||
import cn.easyes.annotation.IndexId;
|
||||
import cn.easyes.annotation.IndexName;
|
||||
import cn.easyes.common.constants.Analyzer;
|
||||
import cn.easyes.common.enums.FieldStrategy;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
@ -18,12 +18,12 @@ import lombok.experimental.Accessors;
|
||||
**/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@TableName(shardsNum = 3, replicasNum = 2, keepGlobalPrefix = true)
|
||||
@IndexName(shardsNum = 3, replicasNum = 2, keepGlobalPrefix = true)
|
||||
public class Document {
|
||||
/**
|
||||
* es中的唯一id,如果你想自定义es中的id为你提供的id,比如MySQL中的id,请将注解中的type指定为customize或直接在全局配置文件中指定,如此id便支持任意数据类型)
|
||||
*/
|
||||
@TableId(type = IdType.CUSTOMIZE)
|
||||
@IndexId(type = IdType.CUSTOMIZE)
|
||||
private String id;
|
||||
/**
|
||||
* 文档标题,不指定类型默认被创建为keyword类型,可进行精确查询
|
||||
@ -33,37 +33,37 @@ public class Document {
|
||||
* 文档内容,指定了类型及存储/查询分词器
|
||||
*/
|
||||
@HighLight(mappingField = "highlightContent")
|
||||
@TableField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_MAX_WORD)
|
||||
@IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_MAX_WORD)
|
||||
private String content;
|
||||
/**
|
||||
* 作者 加@TableField注解,并指明strategy = FieldStrategy.NOT_EMPTY 表示更新的时候的策略为 创建者不为空字符串时才更新
|
||||
*/
|
||||
@TableField(strategy = FieldStrategy.NOT_EMPTY)
|
||||
@IndexField(strategy = FieldStrategy.NOT_EMPTY)
|
||||
private String creator;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fieldType = FieldType.DATE, dateFormat = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
|
||||
@IndexField(fieldType = FieldType.DATE, dateFormat = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
|
||||
private String gmtCreate;
|
||||
/**
|
||||
* es中实际不存在的字段,但模型中加了,为了不和es映射,可以在此类型字段上加上 注解@TableField,并指明exist=false
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
@IndexField(exist = false)
|
||||
private String notExistsField;
|
||||
/**
|
||||
* 地理位置经纬度坐标 例如: "40.13933715136454,116.63441990026217"
|
||||
*/
|
||||
@TableField(fieldType = FieldType.GEO_POINT)
|
||||
@IndexField(fieldType = FieldType.GEO_POINT)
|
||||
private String location;
|
||||
/**
|
||||
* 图形(例如圆心,矩形)
|
||||
*/
|
||||
@TableField(fieldType = FieldType.GEO_SHAPE)
|
||||
@IndexField(fieldType = FieldType.GEO_SHAPE)
|
||||
private String geoLocation;
|
||||
/**
|
||||
* 自定义字段名称
|
||||
*/
|
||||
@TableField(value = "wu-la", fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
|
||||
@IndexField(value = "wu-la", fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
|
||||
private String customField;
|
||||
|
||||
/**
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<artifactId>easy-es</artifactId>
|
||||
<groupId>cn.easy-es</groupId>
|
||||
<version>0.9.40</version>
|
||||
<version>0.9.50</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>easy-es-test</artifactId>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package cn.easyes.test.entity;
|
||||
|
||||
import cn.easyes.annotation.TableField;
|
||||
import cn.easyes.annotation.TableName;
|
||||
import cn.easyes.annotation.IndexField;
|
||||
import cn.easyes.annotation.IndexName;
|
||||
import cn.easyes.common.constants.Analyzer;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
import cn.easyes.common.params.JoinField;
|
||||
@ -13,7 +13,7 @@ import lombok.Data;
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Data
|
||||
@TableName(child = true)
|
||||
@IndexName(child = true)
|
||||
public class Comment {
|
||||
/**
|
||||
* 评论id
|
||||
@ -22,11 +22,11 @@ public class Comment {
|
||||
/**
|
||||
* 评论内容
|
||||
*/
|
||||
@TableField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
|
||||
@IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
|
||||
private String commentContent;
|
||||
/**
|
||||
* 父子关系字段
|
||||
*/
|
||||
@TableField(fieldType = FieldType.JOIN)
|
||||
@IndexField(fieldType = FieldType.JOIN)
|
||||
private JoinField joinField;
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package cn.easyes.test.entity;
|
||||
|
||||
import cn.easyes.annotation.HighLight;
|
||||
import cn.easyes.annotation.TableField;
|
||||
import cn.easyes.annotation.TableId;
|
||||
import cn.easyes.annotation.TableName;
|
||||
import cn.easyes.annotation.IndexField;
|
||||
import cn.easyes.annotation.IndexId;
|
||||
import cn.easyes.annotation.IndexName;
|
||||
import cn.easyes.common.constants.Analyzer;
|
||||
import cn.easyes.common.enums.FieldStrategy;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
@ -21,12 +21,12 @@ import java.util.List;
|
||||
**/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@TableName(shardsNum = 3, replicasNum = 2, keepGlobalPrefix = true, childClass = Comment.class)
|
||||
@IndexName(shardsNum = 3, replicasNum = 2, keepGlobalPrefix = true, childClass = Comment.class)
|
||||
public class Document {
|
||||
/**
|
||||
* es中的唯一id,如果你想自定义es中的id为你提供的id,比如MySQL中的id,请将注解中的type指定为customize或直接在全局配置文件中指定,如此id便支持任意数据类型)
|
||||
*/
|
||||
@TableId(type = IdType.CUSTOMIZE)
|
||||
@IndexId(type = IdType.CUSTOMIZE)
|
||||
private String id;
|
||||
/**
|
||||
* 文档标题,不指定类型默认被创建为keyword类型,可进行精确查询
|
||||
@ -36,37 +36,37 @@ public class Document {
|
||||
* 文档内容,指定了类型及存储/查询分词器
|
||||
*/
|
||||
@HighLight(mappingField = "highlightContent",fragmentSize = 2)
|
||||
@TableField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
|
||||
@IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
|
||||
private String content;
|
||||
/**
|
||||
* 作者 加@TableField注解,并指明strategy = FieldStrategy.NOT_EMPTY 表示更新的时候的策略为 创建者不为空字符串时才更新
|
||||
*/
|
||||
@TableField(strategy = FieldStrategy.NOT_EMPTY, fieldType = FieldType.KEYWORD_TEXT)
|
||||
@IndexField(strategy = FieldStrategy.NOT_EMPTY, fieldType = FieldType.KEYWORD_TEXT)
|
||||
private String creator;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fieldType = FieldType.DATE, dateFormat = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
|
||||
@IndexField(fieldType = FieldType.DATE, dateFormat = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
|
||||
private String gmtCreate;
|
||||
/**
|
||||
* es中实际不存在的字段,但模型中加了,为了不和es映射,可以在此类型字段上加上 注解@TableField,并指明exist=false
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
@IndexField(exist = false)
|
||||
private String notExistsField;
|
||||
/**
|
||||
* 地理位置经纬度坐标 例如: "40.13933715136454,116.63441990026217"
|
||||
*/
|
||||
@TableField(fieldType = FieldType.GEO_POINT)
|
||||
@IndexField(fieldType = FieldType.GEO_POINT)
|
||||
private String location;
|
||||
/**
|
||||
* 图形(例如圆心,矩形)
|
||||
*/
|
||||
@TableField(fieldType = FieldType.GEO_SHAPE)
|
||||
@IndexField(fieldType = FieldType.GEO_SHAPE)
|
||||
private String geoLocation;
|
||||
/**
|
||||
* 自定义字段名称
|
||||
*/
|
||||
@TableField(value = "wu-la", fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
|
||||
@IndexField(value = "wu-la", fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
|
||||
private String customField;
|
||||
|
||||
/**
|
||||
@ -80,12 +80,12 @@ public class Document {
|
||||
/**
|
||||
* 嵌套类型 注意,务必像下面示例一样指定类型为nested及其nested class,否则会导致框架无法正常运行
|
||||
*/
|
||||
@TableField(fieldType = FieldType.NESTED, nestedClass = User.class)
|
||||
@IndexField(fieldType = FieldType.NESTED, nestedClass = User.class)
|
||||
private List<User> users;
|
||||
|
||||
/**
|
||||
* 父子类型 须通过注解在父文档及子文档的实体类中指明其类型为Join,及其父名称和子名称
|
||||
*/
|
||||
@TableField(fieldType = FieldType.JOIN, parentName = "document", childName = "comment")
|
||||
@IndexField(fieldType = FieldType.JOIN, parentName = "document", childName = "comment")
|
||||
private JoinField joinField;
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package cn.easyes.test.entity;
|
||||
|
||||
import cn.easyes.annotation.TableField;
|
||||
import cn.easyes.annotation.TableName;
|
||||
import cn.easyes.annotation.IndexField;
|
||||
import cn.easyes.annotation.IndexName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -25,9 +25,9 @@ import lombok.NoArgsConstructor;
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("faq")
|
||||
@IndexName("faq")
|
||||
public class Faq {
|
||||
@TableField("faq_name")
|
||||
@IndexField("faq_name")
|
||||
private String faqName;
|
||||
private String faqAnswer;
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package cn.easyes.test.entity;
|
||||
|
||||
import cn.easyes.annotation.TableField;
|
||||
import cn.easyes.annotation.IndexField;
|
||||
import cn.easyes.common.constants.Analyzer;
|
||||
import cn.easyes.common.enums.FieldType;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -18,13 +18,13 @@ import java.util.Set;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class User {
|
||||
@TableField(value = "user_name", analyzer = Analyzer.IK_SMART)
|
||||
@IndexField(value = "user_name", analyzer = Analyzer.IK_SMART)
|
||||
private String username;
|
||||
@TableField(exist = false)
|
||||
@IndexField(exist = false)
|
||||
private Integer age;
|
||||
/**
|
||||
* 多级嵌套
|
||||
*/
|
||||
@TableField(fieldType = FieldType.NESTED, nestedClass = Faq.class)
|
||||
@IndexField(fieldType = FieldType.NESTED, nestedClass = Faq.class)
|
||||
private Set<Faq> faqs;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user