Hibernate 搜索字段映射

标签 hibernate full-text-search hibernate-search

Hibernate Search @Field 注释提供了为属性选择索引名称的选项:

...
@Field(name="somethingOrOther")
public String getSomeValue() {
...

用户指南对于 @Field 注释的 name 属性是这样说的:

name : describe under which name, the property should be stored in the Lucene Document. The default value is the property name (following the JavaBeans convention)

有什么方法可以将带注释的 bean 的名称设置为另一个值吗?

类似的东西

...
public String getFieldName() {
   return fieldName;
}

@Field(name="{fieldName}")
public String getFieldValue() {
   return fieldValue;
}

其中 {fieldName} 将替换为 getFieldName() 的结果。

最佳答案

可以使用自定义FieldBridge来完成。实现 FieldBridge 接口(interface)时,您自己的代码负责将值添加到 Lucene 文档中,因此实际上您可以编写任何您想要的内容。

FieldBridge documentation

关于Hibernate 搜索字段映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8210250/

相关文章:

sql-server - 为什么我的单字符全文搜索不起作用?

java - hibernate 搜索 : Search any part of the field without losing field's content while indexing

java - 带有枚举字段的 Hibernate Search/Lucene 范围查询不返回任何结果

java - 如何使用 hibernate session 方法更新映射实体类的实例?

java - hibernate HQL元素错误

java - 向 Web 应用程序添加搜索功能和页面支持

elasticsearch - 使用ElasticSearch进行Smartcase搜索/突出显示

java - 如何在hibernate中填充相同pojo类型的两个子成员变量

java - 复合键连接列

hibernate - Elasticsearch 需要数据库吗?