`
zhaolei415
  • 浏览: 166659 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

hibrnate和lucene的集成

阅读更多
Lucene是一个高性能的java搜索引擎库,可以从 Apache软件基金组织获取。Hibernate Annotations包括一个注解包,它允许把任何域模型对象标记为可索引的,并且对任何经由Hibernate进行持续化的实例,Hibernate 都会为之维护一个对应的Lucene索引。

使用Lucene为实体建立索引

注解域模型

首先,必须将一个持久类声明为@Indexed:

@Entity
@Indexed(index="indexes/essays")
public class Essay {
...
}

属性index是告诉Hibernate, Lucene索引信息所在的位置(你文件系统的某个目录)。如果你想为所有的Lucene索引定义一个根目录,你可以在配置文件中用属性hibernate.lucene.index_dir进行配置。
Lucene索引包括四种字段:
keyword字段,text字段,unstored字段和unindexed字段。Hibernate注解提供了将实体属性标记为前三种被索引字段的注解。
@Entity
@Indexed(index="indexes/essays")
public class Essay {
...@Id
@Keyword(id=true)
public Long getId(){ return id; } @Text(name="Abstract")
public String getSummary(){ return summary; } @Lob
@Unstored
public String getText(){ return text; } }
这些注解定义了一个带有三个字段的索引:Id, Abstract 和
Text

注意:你必须在你的实体类的标志属性上指定@Keyword(id=true) 。

用于对元素建立索引的分析器类是可以通过hibernate.lucene.analyzer属性进行配置的。如果没有定义,则把org.apache.lucene.analysis.standard.StandardAnalyzer作为缺省。

激活自动索引
我们激活用于帧听三类Hibernate事件的LuceneEventListener,这些事件会在变更被提交至数据库后产生。

...
<event type="post-commit-update"

<event type="post-commit-insert"

<event type="post-commit-delete"


review 完毕:

1. Apache Software Foundation, Apache软件基金组织
2. domain model object,领域模型对象
3. First, we must declare a persistent class as @Indexed
  首先我们必须将持久类声明为@Indexed
4. The <literal>index</literal> attribute tells Hibernate where the Lucene index is located
  属性index告知Hibernate,Lucene索引信息所在的位置
5. If you wish to define a base directory for all lucene indexes,
  如果你想为......定义一个根目录(base directory)
6. one of the first three kinds of indexed fields.
  ......被索引字段......
7. These annotations define an index with three fields:
  上述注解定义了一个带有三个字段的索引:
8. on the identifier property of
  标识属性(identifier property)
9. The analyzer class used to index the elements is configurable through the <literal>hibernate.lucene.analyzer</literal> property.
  用于对元素建立索引的分析器类是可以通过......属性进行配置的
10. Enabling automatic indexing
  激活自动索引
11. we enable the <literal>LuceneEventListener</literal> for
the three Hibernate events that occur after changes are committed to the
database.
  我们激活用于帧听三类Hibernate事件的LuceneEventListener,这些事件会在变更被提交至数据库后产生。








分享到:
评论

相关推荐

    Struts2.3.8整合Hibernate4.2,Spring3.2lucene 3 6 2 SSH整合1.0版

    Struts2.3.8整合Hibernate4.2,Spring3.2lucene 3 6 2 SSH整合1.0版

    ssh集成Lucene4.7demo

    Struts2.3+spring4+hibernate4+Lucene4.7+IKAnalyzer,中文分词,高亮显示,附带MySQL8000条测试数据。仅供学习参考

    Hibernate搜索框架HibernateSearch.zip

    Hibernate Search主要有以下功能特点:1,功能强大,配置简单 - 配置只需要修改persistence.xml(JPA),hibernate.cfg.xml(Hibernate)2,支持Hibernate,以及EJB3 JPA标准应用3,集成全文搜索引擎Lucene - Lucene...

    hibernate annotations

    Hibernate 注解的说明文档 第 1 章 创建一个注解项目 第 2 章 实体Bean 第 3 章 通过XML覆写元数据 第 4 章 Hibernate验证器 第 5 章 Hibernate与Lucene集成

    Hibernate Annotations 中文文档

    Hibernate Annotations API 中文文档 前言 1. 创建一个注解项目 1.1. 系统需求 1.2. 系统配置 ...5. Hibernate与Lucene集成 5.1. 使用Lucene为实体建立索引 5.1.1. 注解领域模型 5.1.2. 启用自动索引

    hibernate annotation 中文文档

    前言 1. 翻译说明 2. 版权声明 前言 1. 创建一个注解项目 1.1. 系统需求 1.2. 系统配置 ...5. Hibernate与Lucene集成 5.1. 使用Lucene为实体建立索引 5.1.1. 注解领域模型 5.1.2. 启用自动索引 A. 术语表

    harmonyos2-grails-hibernate-search-plugin:将HibernateSearch功能集成到Grails

    和声2 Grails Hibernate 搜索插件 这个插件旨在通过几个步骤将 Hibernate Search 功能集成到 Grails 中。 入门 如果你不想从 开始,你可以开始一个新的项目: 并将以下内容添加到您的依赖项中 compile("org.grails....

    jboss seam

    为轻量化的异步性集成了EJB Timer Service和Quartz,为工作流集成了jBPM,为业务规则集成了JBoss规则,为电子邮件集成了Meldware Mail,为完整的文本搜索集成了Hibernate Search和Lucene,为消息集成了JMS,以及为...

    Hibernate Search 3.0 GA

    它是hibernate对著名的全文检索系统Lucene的一个集成方案,作用在于对数据表中某些内容庞大的字段(如声明为text的字段)建立全文索引,这样通过hibernate search就可以对这些字段进行全文检索后获得相应的POJO,...

    hibernate-search-5.3.0.Final.chm

    它是hibernate对著名的全文检索系统Lucene的一个集成方案,作用在于对数据表中某些内容庞大的字段(如声明为text的字段)建立全文索引,这样通过hibernate search就可以对这些字段进行全文检索后获得相应的POJO,...

    JAVA WEB典型模块与项目实战大全

    3.4 实现spring、struts2.x和hibernate框架集成  3.5 小结  第2篇 典型模块开发  第4章 在线文本编辑器(fckeditor)  4.1 分析fckeditor在线文本编辑器  4.2 fckeditor在线文本编辑器初级应用  4.3 ...

    JAVA WEB典型模块与项目实战大全.part2(第二卷)

    第3章 实现各种框架的集成 第2篇 典型模块开发 第4章 在线文本编辑器(FCKeditor) 第5章 验证模块(JSP+Serylet+JSValldation) 第6章 网络硬盘(JSP+Servlet) 第7章 网站统计模块(JSP+Servlet) 第8章 网络购物车(JSP...

    JAVA WEB典型模块与项目实战大全.part4

    第3章 实现各种框架的集成 第2篇 典型模块开发 第4章 在线文本编辑器(FCKeditor) 第5章 验证模块(JSP+Serylet+JSValldation) 第6章 网络硬盘(JSP+Servlet) 第7章 网站统计模块(JSP+Servlet) 第8章 网络购物车(JSP...

    java文集

    正则表达式 lucene索引合并 探查Weblogic JDBC Multipool 问题 struts通用Exception处理 Grails中默认数据库HSQLDB点滴 从request获取各种路径总结 DIV实现的表格自动伸张与收缩 java 邮件...

    JAVA WEB典型模块与项目实战大全.part3(第三卷)

    第3章 实现各种框架的集成 第2篇 典型模块开发 第4章 在线文本编辑器(FCKeditor) 第5章 验证模块(JSP+Serylet+JSValldation) 第6章 网络硬盘(JSP+Servlet) 第7章 网站统计模块(JSP+Servlet) 第8章 网络购物车(JSP...

    可直接使用的appfuse项目

    AppFuse是一个集成了众多当前最流行开源框架与工具(包括Hibernate、ibatis、Struts、Spring、DBUnit、Maven、Log4J、Struts Menu、Xdoclet、SiteMesh、OSCache、JUnit、JSTL等(现在还有lucene的,无敌了))于一身的...

    JAVA WEB典型模块与项目实战大全.part1(第一卷)

    第15章 在线文件上传和下载(Struts 2.X+FileUpload) 第16章 网上投票系统(Struts2.X+JFreeChat) 第17章 商业银行网上账户管理系统(Struts2.X) 第18章 Hibernate分页系统(Hibernate3.0) 第19章 生成保表...

    Java学习路线图.pdf

    * Struts/Hibernate/Spring Framework 基础:掌握 Struts、Hibernate 和 Spring Framework 等整合框架的使用。 * MyBatis/容器基础:掌握 MyBatis 和容器技术的使用。 * Tomcat/Jetty/WebLogic/WebSphere/WildFly ...

    java开源包1

    同时保持蒸提供全面的支持,无缝集成的IDE(语法着色,代码导航,重构等)的语法和操作代码完全分离。最大限度地减少时间和费用开发自定义的DSL(领域特定语言在Java)要求。 日志服务器 Apache Flume.tar Flume 是...

    java开源包11

    同时保持蒸提供全面的支持,无缝集成的IDE(语法着色,代码导航,重构等)的语法和操作代码完全分离。最大限度地减少时间和费用开发自定义的DSL(领域特定语言在Java)要求。 日志服务器 Apache Flume.tar Flume 是...

Global site tag (gtag.js) - Google Analytics