hibernate search 嵌套索引

本文介绍Hibernate Search模块的基本配置及如何与Lucene集成实现全文检索。通过具体示例展示了如何将一对多关联关系的实体类Book和Author进行索引,并使用Lucene进行高效搜索。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

官方文档
[img]http://docs.jboss.org/hibernate/stable/search/reference/en/html/ch01s03.html[/img]

[b]最基本配置[/b]
<property name="hibernate.search.default.directory_provider" 
value="org.hibernate.search.store.FSDirectoryProvider"/>

<property name="hibernate.search.default.indexBase" value="/var/lucene/indexes"/>


[b]一个一对多关联的例子[/b]
[color=red]配置前[/color]
package example;
...
@Entity
public class Book {

@Id
@GeneratedValue
private Integer id;

private String title;

private String subtitle;

@ManyToMany
private Set<Author> authors = new HashSet<Author>();

private Date publicationDate;

public Book() {
}

// standard getters/setters follow here
...
}


package example;
...
@Entity
public class Author {

@Id
@GeneratedValue
private Integer id;

private String name;

public Author() {
}

// standard getters/setters follow here
...
}


配置后

package example;
...
@Entity
@Indexed
public class Book {

@Id
@GeneratedValue
@DocumentId
private Integer id;

@Field(index=Index.TOKENIZED, store=Store.NO)
private String title;

@Field(index=Index.TOKENIZED, store=Store.NO)
private String subtitle;

@IndexedEmbedded
@ManyToMany
private Set<Author> authors = new HashSet<Author>();

@Field(index = Index.UN_TOKENIZED, store = Store.YES)
@DateBridge(resolution = Resolution.DAY)
private Date publicationDate;

public Book() {
}

// standard getters/setters follow here
...
}


package example;
...
@Entity
public class Author {

@Id
@GeneratedValue
private Integer id;

@Field(index=Index.TOKENIZED, store=Store.NO)
private String name;

public Author() {
}

// standard getters/setters follow here
...
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值