Hibernate Lucene 的集成

Hibernate Lucene Integration

Hibernate Lucene 的集成

Lucene is a high-performance Java search engine library available from
the Apache Software Foundation. Hibernate Annotations includes a package of
annotations that allows you to mark any domain model object as indexable and
have Hibernate maintain a Lucene index of any instances persisted via
Hibernate.

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

Using Lucene to index your entities

使用Lucene为实体建立索引

Annotating your domain model

注解域模型

First, we must declare a persistent class as
@Indexed:

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

programlisting

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

 

The index attribute tells Hibernate where the
Lucene index is located (a directory on your file system). If you wish
to define a base directory for all lucene indexes, you can use the
hibernate.lucene.index_dir property in your
configuration file.

属性index是告诉Hibernate, Lucene索引信息所在的位置(你文件系统的某个目录)。如果你想为所有的Lucene索引定义一个根目录,你可以在配置文件中用属性hibernate.lucene.index_dir进行配置。

Lucene indexes contain four kinds of fields:
keyword fields, text fields,
unstored fields and unindexed
fields. Hibernate Annotations provides annotations to mark a property of
an entity as one of the first three kinds of indexed fields.

Lucene索引包括四种字段:

keyword字段,text字段,unstored字段和unindexed字段。Hibernate注解提供了将实体属性标记为前三种被索引字段的注解。

programlisting

@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; } }

 

These annotations define an index with three fields:
Id, Abstract and
Text.

这些注解定义了一个带有三个字段的索引:Id, Abstract
Text

Note: you must specify
@Keyword(id=true) on the identifier property of your
entity class.

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

The analyzer class used to index the elements is configurable
through the hibernate.lucene.analyzer property. If
none defined,
org.apache.lucene.analysis.standard.StandardAnalyzer
is used as the default.

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

Enabling automatic indexing

激活自动索引

Finally, we enable the LuceneEventListener for
the three Hibernate events that occur after changes are committed to the
database.

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

programlisting

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

<event type="post-commit-insert"></event>

<event type="post-commit-delete"></event>

 

review 完毕:

1. Apache Software Foundation, Apache软件基金组织
2. domain model object,领域模型对象
3. First, we must declare a persistent class as @Indexed
  首先我们必须将持久类声明为@Indexed
4. The <literal></literal> index 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></literal> hibernate.lucene.analyzer property.
  用于对元素建立索引的分析器类是可以通过......属性进行配置的
10. Enabling automatic indexing
  激活自动索引
11. we enable the <literal></literal> LuceneEventListener for
the three Hibernate events that occur after changes are committed to the
database.
  我们激活用于帧听三类Hibernate事件的LuceneEventListener,这些事件会在变更被提交至数据库后产生。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值