Hibernate SearchHibernate搜索框架
Hibernate Search 的作用是對(duì)數(shù)據(jù)庫中的數(shù)據(jù)進(jìn)行檢索的。它是 hibernate 對(duì)著名的全文檢索系統(tǒng) Lucene 的一個(gè)集成方案,作用在于對(duì)數(shù)據(jù)表中某些內(nèi)容龐大的字段(如聲明為 text 的字段)建立全文索引,這樣通過 hibernate search 就可以對(duì)這些字段進(jìn)行全文檢索后獲得相應(yīng)的 POJO,從而加快了對(duì)內(nèi)容龐大字段進(jìn)行模糊搜索的速度(sql 語句中 like 匹配)。
Hibernate Search 自動(dòng)從 Hibernate ORM 實(shí)體中提取數(shù)據(jù),以將其推送到本地 Apache Lucene 索引或遠(yuǎn)程 Elasticsearch 索引。
Hibernate Search主要有以下功能特點(diǎn):
- 通過注釋或 programmatic API 將實(shí)體屬性聲明性映射到索引字段。
- 數(shù)據(jù)庫中所有實(shí)體的按需大量索引,以使用預(yù)先存在的數(shù)據(jù)初始化索引。
- 通過 Hibernate ORM 會(huì)話修改實(shí)體的即時(shí)自動(dòng)索引 ,以始終保持索引最新。
- 一種搜索 DSL ,可輕松構(gòu)建全文搜索查詢并將命中結(jié)果檢索為 Hibernate ORM 實(shí)體。
- 還有更多:分析器的配置、 搜索 DSL 中的許多不同謂詞和排序、空間支持。搜索查詢返回 projections 而不是 entities、聚合、使用橋接的高級(jí)自定義映射...
@Entity // This entity is mapped to an index @Indexed public class Book { // The entity ID is the document ID @Id @GeneratedValue private Integer id; // This property is mapped to a document field @FullTextField private String title; @ManyToMany // Authors will be embedded in Book documents @IndexedEmbedded private Set<Author> authors = new HashSet<>(); // Getters and setters // ... } @Entity public class Author { @Id @GeneratedValue private Integer id; // This property is mapped to a document field @FullTextField private String name; @ManyToMany(mappedBy = "authors") private Set<Book> books = new HashSet<>(); // Getters and setters // ... }
評(píng)論
圖片
表情
