1.2. 索引注解
当您在缓存中启用索引时,您可以将 Data Grid 配置为创建索引。您还需要为 Data Grid 提供缓存中实体的结构化表示,以便它实际上可以索引它们。
有两个注解控制 Data Grid 索引的实体和字段:
@indexed- 指明数据网格索引的实体或 Protobuf 消息类型。
@field指明 Data Grid 索引并具有以下属性的字段:
Expand 属性 描述 值 index控制 Data Grid 是否包含索引中的字段。
index.YES或Index.NOStore允许 Data Grid 将字段存储在索引中,以便您可以将它们用于预测。
store.YES或Store.NO.对于需要用于排序的字段,使用Store.YES和 setsortable = true。分析包括全文本搜索中的字段。
analyze.NO或指定分析器定义
远程缓存
您可以通过两种方式为远程缓存提供索引注解:
-
使用
@ProtoDoc ("@Indexed")和@ProtoDoc ("@Field (…) ")直接注解您的 Java 类。
然后,在将 Protobuf 模式.proto文件上传到 Data Grid Server 之前,生成 Protobuf 模式。 直接使用
@Indexed和@Field (…)直接注解 Protobuf 模式。
然后,将 Protobuf 模式上传到 Data Grid Server。例如,以下模式使用
@Field注释:/** * @Field(analyze = Analyze.YES, store = Store.YES, sortable = true) */ required string street = 1;
/** * @Field(analyze = Analyze.YES, store = Store.YES, sortable = true) */ required string street = 1;Copy to Clipboard Copied! Toggle word wrap Toggle overflow 通过在
@Field注释中包含store.YES和sortable = true,您可以使用street字段排序查询,而无需遇到警告消息或意外的结果。
嵌入式缓存
对于嵌入式缓存,您可以根据 Data Grid 如何存储您的条目,为 Java 类添加索引注解。
使用 @Indexed 和 @Field 注释,以及其他 Hibernate 搜索注释,如 @FullTextField。