2008-03-31

Chapter 3. hibernate search configuration

关键字: hibernate search
Apache Lucene has a 概念 of Directory to store the index files
这个目录实现可以自定义。但是Lucene绑定文件系统FSDirectoryProvider 内存模式memory(RAMDirectoryProvider)2种实现。Hibernate Search 提供DirectoryProvider 概念处理Lucene目录问题。内建Directory Providers

1 org.hibernate.search.store.FSDirectoryProvider
2 org.hibernate.search.store.FSMasterDirectoryProvider
3 org.hibernate.search.store.FSSlaveDirectoryProvider
4 org.hibernate.search.store.RAMDirectoryProvider

2,3实现应该是为JMS模式的集群部署设置的。单机部署不需要。如果这些都不合适你。可以实现org.hibernate.store.DirectoryProvider interface

每个被索引的实体被分配一个lucene索引(一个索引能被多个实体共享。虽然大部分时候不这么用。)你能配置索引通过属性prefixed by hibernate.search.indexname。

默认属性继承给所有的索引可以被定义使用 the prefix hibernate.search.default.

定义索引目录provider。可以使用hibernate.search.indexname.directory_provider
-------------------------------------------------
hibernate.search.Rules.directory_provider org.hibernate.search.store.RAMDirectoryProvider

将Rules索引设置为内存模式。

hibernate.search.default.directory_provider org.hibernate.search.store.FSDirectoryProvider
hibernate.search.default.indexBase=/usr/lucene/indexes

上面2行配置将在/usr/lucene/indexes/Status保存Stauts对象的索引信息
-------------------------------------------------

3.4索引切割

在一些极端情况,涉及到大尺寸的是索引文件。必须切割成多个索引文件。但不建议这样除非达到巨大的数量并且更新索引的速度很慢。主要的缺点是查询将变慢。因为不得不为单个搜索打开更多的文件。换句话说,除非迫不得已不要这样做!
尽管如此,hibernate search依然允许你索引到多个子索引中,通过使用IndexShardingStrategy.默认情况是不打开的。除非分割的数量被配置了。
引用
hibernate.search.<indexName>.sharding_strategy.nbr_of_shards 5


这部分内容还有很多,参考英文文档。因为我暂时不需要这个!

3.6打开hibernate search和自动索引功能

Hibernate Search is enabled out of the box when using Hibernate Annotations or Hibernate EntityManager.
如果需要关闭,设置hibernate.search.autoregister_listeners为false

Note that
引用
there is no performance runtime when the listeners are enabled while no entity is indexable.


要使用hibernate search功能。添加FullTextIndexEventListener。
引用
Once again, such a configuration is not useful with
Hibernate Annotations or Hibernate EntityManager.

再说一次。这个配置对Annotations EntityManager无效??什么意思?没明白。

Be sure to add the appropriate jar files in your classpath

添加合适的包。。

hibernate-search.jar lucene-core.*.jar

如果使用Hibernate Core 3.2.6及以上版本,确保添加了额外的事件监听以应付集合事件。(collection events)
引用
<event type="post-collection-recreate"/>
<listener class="org.hibernate.search.event.FullTextIndexCollectionEventListener"/>
</event>


这些额外的事件监听器是在3.2.6被引入的。注意FullTextIndexCollectionEventListener的用法。你必须明确的引用这些事件监听除非你使用Hibernate Annotations3.3.1及以上。

3.6.2自动索引。

默认自动在通过hibernate添加删除更新时索引。一些时间期望关闭这些功能。如索引为只读或者索引更新批量see Chapter 6, Manual indexing

引用
hibernate.search.indexing_strategy manual
评论
liuzongan 2008-04-24
谢谢你的翻译
发表评论

您还没有登录,请登录后发表评论

wutao8818
搜索本博客
我的相册
B72616b1-874a-316f-9919-fa398e490c9f-thumb
safari
共 8 张
最近加入圈子
存档
最新评论