没有合适的资源?快使用搜索试试~ 我知道了~
hibernate_search.pdf
试读
65页
需积分: 0 4 下载量 201 浏览量
更新于2009-03-19
收藏 387KB PDF 举报
标题:hibernate_search.pdf
描述与标签:此文档详细介绍了Hibernate Search的使用与配置,一个为Hibernate ORM提供全文搜索功能的扩展。该文档版本为3.1.0.GA,深入探讨了如何将Apache Lucene集成到Hibernate ORM中,以实现高性能的全文检索。
### 重要知识点概览:
#### 1. 入门篇(Getting started)
- **系统需求**:阐述了运行Hibernate Search所需的硬件和软件环境。
- **使用Maven**:指导如何通过Maven管理Hibernate Search依赖,简化项目构建过程。
- **配置**:涵盖Hibernate Search的基本配置,包括如何在应用程序中启用搜索功能。
- **索引化**:介绍如何创建、更新或删除索引,是全文搜索的基础。
- **搜索**:讲解如何利用Hibernate Search执行查询,获取结果集。
- **分析器**:解释如何使用分析器对文本进行预处理,如分词、去除停用词等,提高搜索准确性。
- **下一步行动**:指引用户探索更高级的主题和功能。
#### 2. 架构(Architecture)
- **概述**:提供了Hibernate Search的整体架构图,便于理解各组件间的关系。
- **后端**:
- **Lucene**:作为默认后端,用于存储和搜索索引数据。
- **JMS**:通过Java消息服务实现分布式搜索解决方案。
- **工作执行**:区分同步与异步模式,以适应不同场景下的性能需求。
- **读取策略**:共享与非共享读取策略的区别,以及自定义读取策略的可能性。
#### 3. 配置(Configuration)
- **目录配置**:指导如何设置Lucene索引存储位置。
- **分片索引**:介绍如何将索引数据分布在多个物理位置,以提升性能和可伸缩性。
- **索引共享**:讨论实体间的索引共享机制,优化存储和检索效率。
- **工作者配置**:设定用于索引化操作的线程池参数。
- **JMS主/从配置**:在分布式环境中配置主节点和从节点,实现负载均衡。
- **读取策略配置**:自定义读取策略,以满足特定业务需求。
- **启用Hibernate Search与自动索引**:确保搜索功能的可用性和实体变更时的自动索引更新。
- **调整Lucene索引性能**:优化索引构建和查询性能的方法。
#### 4. 映射实体到索引结构(Mapping entities to the index structure)
- **基本映射**:如何将实体属性映射到索引字段。
- **多次映射属性**:允许同一属性在索引中存在多个实例,用于多字段查询。
- **嵌入式和关联对象**:处理复杂数据类型,如嵌套实体和关联实体的索引化。
- **提升因子**:调节某些字段在搜索排名中的重要性。
- **分析器**:定义和使用分析器,处理文本数据的规范化和解析。
- **Property/Field Bridge**:桥接器用于转换实体属性,使之适应索引需求。
- **提供自定义ID**:允许使用实体的自定义ID作为索引键。
#### 5. 查询(Querying)
- **构建查询**:Lucene查询和Hibernate Search查询的构造方法,包括通用查询、分页、排序和结果获取策略。
- **结果处理**:考虑性能因素,控制结果集大小,使用结果转换器,并理解查询结果。
- **过滤器**:基于预定义条件筛选查询结果。
- **优化查询过程**:减少查询延迟,提高响应速度。
- **原生Lucene查询**:直接使用Lucene API进行查询,适用于高级搜索场景。
#### 6. 手动索引(Manual indexing)
- **索引化**:手动触发索引更新,适用于非自动索引更新场景。
- **清除**:从索引中移除实体记录。
#### 7. 索引优化(Index Optimization)
- **自动优化**:定期执行的自动优化过程,以维护索引的高效运行。
- **手动优化**:允许用户手动启动优化任务,以即时改善索引性能。
通过上述知识点,读者可以全面了解Hibernate Search的功能、架构、配置和使用技巧,从而在实际项目中有效应用全文搜索技术,提升数据检索的准确性和效率。
Hibernate Search
Apache Lucene Integration
Version: 3.1.0.GA
Table of Contents
Preface ............................................................................................................................................iv
1. Getting started ............................................................................................................................1
1.1. System Requirements .........................................................................................................1
1.2. Using Maven .....................................................................................................................1
1.3. Configuration .....................................................................................................................2
1.4. Indexing ............................................................................................................................5
1.5. Searching ...........................................................................................................................6
1.6. Analyzer ............................................................................................................................7
1.7. What's next ........................................................................................................................9
2. Architecture .............................................................................................................................. 10
2.1. Overview ......................................................................................................................... 10
2.2. Back end ......................................................................................................................... 10
2.2.1. Back end types ...................................................................................................... 11
2.2.1.1. Lucene ....................................................................................................... 11
2.2.1.2. JMS ........................................................................................................... 11
2.2.2. Work execution ..................................................................................................... 12
2.2.2.1. Synchronous ............................................................................................... 12
2.2.2.2. Asynchronous ............................................................................................ 13
2.3. Reader strategy ................................................................................................................ 13
2.3.1. Shared .................................................................................................................. 13
2.3.2. Not-shared ............................................................................................................ 13
2.3.3. Custom ................................................................................................................. 13
3. Configuration ............................................................................................................................ 14
3.1. Directory configuration .................................................................................................... 14
3.2. Sharding indexes .............................................................................................................. 16
3.3. Sharing indexes (two entities into the same directory) ......................................................... 17
3.4. Worker configuration ....................................................................................................... 17
3.5. JMS Master/Slave configuration ........................................................................................ 18
3.5.1. Slave nodes ........................................................................................................... 19
3.5.2. Master node .......................................................................................................... 20
3.6. Reader strategy configuration ............................................................................................ 21
3.7. Enabling Hibernate Search and automatic indexing ............................................................ 21
3.7.1. Enabling Hibernate Search ..................................................................................... 21
3.7.2. Automatic indexing ............................................................................................... 22
3.8. Tuning Lucene indexing performance ................................................................................ 22
4. Mapping entities to the index structure ..................................................................................... 26
4.1. Mapping an entity ............................................................................................................ 26
4.1.1. Basic mapping ....................................................................................................... 26
4.1.2. Mapping properties multiple times .......................................................................... 28
4.1.3. Embedded and associated objects ........................................................................... 28
4.1.4. Boost factor .......................................................................................................... 31
4.1.5. Analyzer ............................................................................................................... 32
4.1.5.1. Analyzer definitions .................................................................................... 33
4.1.5.2. Available analyzers ..................................................................................... 34
4.1.5.3. Analyzer discriminator (experimental) ......................................................... 35
4.1.5.4. Retrieving an analyzer ................................................................................ 36
4.2. Property/Field Bridge ....................................................................................................... 37
4.2.1. Built-in bridges ..................................................................................................... 37
Hibernate 3.1.0.GA ii
4.2.2. Custom Bridge ...................................................................................................... 38
4.2.2.1. StringBridge ............................................................................................... 38
4.2.2.2. FieldBridge ................................................................................................ 40
4.2.2.3. ClassBridge ................................................................................................ 41
4.3. Providing your own id ...................................................................................................... 42
4.3.1. The ProvidedId annotation ..................................................................................... 42
5. Querying ................................................................................................................................... 44
5.1. Building queries ............................................................................................................... 45
5.1.1. Building a Lucene query ........................................................................................ 45
5.1.2. Building a Hibernate Search query .......................................................................... 45
5.1.2.1. Generality .................................................................................................. 45
5.1.2.2. Pagination .................................................................................................. 45
5.1.2.3. Sorting ....................................................................................................... 46
5.1.2.4. Fetching strategy ........................................................................................ 46
5.1.2.5. Projection ................................................................................................... 47
5.2. Retrieving the results ........................................................................................................ 48
5.2.1. Performance considerations .................................................................................... 48
5.2.2. Result size ............................................................................................................ 48
5.2.3. ResultTransformer ................................................................................................. 49
5.2.4. Understanding results ............................................................................................ 49
5.3. Filters .............................................................................................................................. 50
5.4. Optimizing the query process ............................................................................................ 53
5.5. Native Lucene Queries ..................................................................................................... 54
6. Manual indexing ....................................................................................................................... 55
6.1. Indexing .......................................................................................................................... 55
6.2. Purging ............................................................................................................................ 56
7. Index Optimization ................................................................................................................... 57
7.1. Automatic optimization .................................................................................................... 57
7.2. Manual optimization ......................................................................................................... 57
7.3. Adjusting optimization ..................................................................................................... 58
8. Advanced features ..................................................................................................................... 59
8.1. SearchFactory .................................................................................................................. 59
8.2. Accessing a Lucene Directory ........................................................................................... 59
8.3. Using an IndexReader ...................................................................................................... 59
8.4. Customizing Lucene's scoring formula .............................................................................. 60
Hibernate Search
Hibernate 3.1.0.GA iii
Preface
Full text search engines like Apache Lucene are very powerful technologies to add efficient free text search
capabilities to applications. However, Lucene suffers several mismatches when dealing with object domain
model. Amongst other things indexes have to be kept up to date and mismatches between index structure and
domain model as well as query mismatches have to be avoided.
Hibernate Search addresses these shortcomings - it indexes your domain model with the help of a few annota-
tions, takes care of database/index synchronization and brings back regular managed objects from free text
queries. To achieve this Hibernate Search is combining the power of Hibernate [http://www.hibernate.org] and
Apache Lucene [http://lucene.apache.org].
Hibernate 3.1.0.GA iv
Chapter 1. Getting started
Welcome to Hibernate Search! The following chapter will guide you through the initial steps required to integ-
rate Hibernate Search into an existing Hibernate enabled application. In case you are a Hibernate new timer we
recommend you start here [http://hibernate.org/152.html].
1.1. System Requirements
Table 1.1. System requirements
Java Runtime A JDK or JRE version 5 or greater. You can down-
load a Java Runtime for Windows/Linux/Solaris here
[http://java.sun.com/javase/downloads/].
Hibernate Search hibernate-search.jar and all runtime dependencies
from the lib directory of the Hibernate Search distri-
bution. Please refer to README.txt in the lib direct-
ory to understand which dependencies are required.
Hibernate Core This instructions have been tested against Hibernate
3.3.x. You will need hibernate-core.jar and its
transitive dependencies from the lib directory of the
distribution. Refer to README.txt in the lib directory
of the distribution to determine the minimum runtime
requirements.
Hibernate Annotations Even though Hibernate Search can be used without
Hibernate Annotations the following instructions will
use them for basic entity configuration (@Entity,
@Id, @OneToMany,...). This part of the configura-
tion could also be expressed in xml or code.
However, Hibernate Search itself has its own set of
annotations (@Indexed, @DocumentId, @Field,...)
for which there exists so far no alternative configura-
tion. The tutorial is tested against version 3.4.x of Hi-
bernate Annotations.
You can download all dependencies from the Hibernate download site [http://www.hibernate.org/6.html]. You
can also verify the dependency versions against the Hibernate Compatibility Matrix
[http://www.hibernate.org/6.html#A3].
1.2. Using Maven
Instead of managing all dependencies manually, maven users have the possibility to use the JBoss maven re-
pository [http://repository.jboss.com/maven2]. Just add the JBoss repository url to the repositories section of
your pom.xml or settings.xml:
Example 1.1. Adding the JBoss maven repository to settings.xml
Hibernate 3.1.0.GA 1
剩余64页未读,继续阅读
资源推荐
资源评论
189 浏览量
107 浏览量
104 浏览量
161 浏览量
192 浏览量
5星 · 资源好评率100%
127 浏览量
5星 · 资源好评率100%
2011-11-25 上传
5星 · 资源好评率100%
2011-11-25 上传
5星 · 资源好评率100%
2011-12-01 上传
130 浏览量
194 浏览量
2022-03-07 上传
139 浏览量
2010-04-02 上传
2007-07-12 上传
资源评论
train8k
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 没用333333333333333333333333333333
- 基于Vue和SpringBoot的企业员工管理系统2.0版本设计源码
- 【C++初级程序设计·配套源码】第2期-基本数据类型
- 基于Java和Vue的kopsoftKANBAN车间电子看板设计源码
- 影驰战将PS3111 东芝芯片TT18G23AIN开卡成功分享,图片里面画线的选项很重要
- 【C++初级程序设计·配套源码】第1期-语法基础
- 基于JavaScript、CSS、HTML的简易DOM版飞机游戏设计源码
- 基于Java开发的日程管理FlexTime应用设计源码
- SM2258XT-BGA144-4BGA180-6L-R1019 三星KLUCG4J1CB B0B1颗粒开盘工具 , EC, 3A, 94, 43, A4, CA 七彩虹SL300这个固件有用
- GJB 5236-2004 军用软件质量度量
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功