确保将实体添加到休眠搜索索引
Ensure entity is added to hibernate search index
我们目前有一个流程,可以总结如下:
- 从批量加载过程中插入实体 A 的列表。
- 在指定日期过后更新这些实体的状态。
我们使用 hibernate search 来索引实体 A 的一些属性。但是,我们也有一个要求,即在状态更新之前我们不索引该实体。
目前,我们在索引时使用 EntityIndexingInterceptor 检查是否根据其状态排除实体。
问题是我们没有为状态字段本身建立索引 - 所以当它发生变化时,hibernate 将其添加到索引的透明机制不会应用,而且永远不会添加。
有没有更好的方法能够强制 hibernate 将其添加到索引而不将字段本身添加到索引?我们目前每晚都重建索引,这通常没问题,但仍然会留下一个 window,在下一次重建之前,实体可能无法搜索。
您使用的是哪个版本的 Hibernate Search?使用拦截器时应自动禁用脏检查优化:
Dirty checking optimization is disabled when interceptors are used. Dirty checking optimization does check what has changed in an entity and only triggers an index update if indexed properties are changed. The reason is simple, your interceptor might depend on a non indexed property which would be ignored by this optimization.
(来自 the documentation)
如果不是,请向复制者报告问题,或者至少提及您正在使用的 Hibernate Search/Hibernate ORM 的确切版本:JIRA, test case templates
在我们修复此问题之前(如果它实际上是一个错误),您始终可以显式禁用脏检查优化:
hibernate.search.enable_dirty_check false
我们目前有一个流程,可以总结如下:
- 从批量加载过程中插入实体 A 的列表。
- 在指定日期过后更新这些实体的状态。
我们使用 hibernate search 来索引实体 A 的一些属性。但是,我们也有一个要求,即在状态更新之前我们不索引该实体。
目前,我们在索引时使用 EntityIndexingInterceptor 检查是否根据其状态排除实体。
问题是我们没有为状态字段本身建立索引 - 所以当它发生变化时,hibernate 将其添加到索引的透明机制不会应用,而且永远不会添加。
有没有更好的方法能够强制 hibernate 将其添加到索引而不将字段本身添加到索引?我们目前每晚都重建索引,这通常没问题,但仍然会留下一个 window,在下一次重建之前,实体可能无法搜索。
您使用的是哪个版本的 Hibernate Search?使用拦截器时应自动禁用脏检查优化:
Dirty checking optimization is disabled when interceptors are used. Dirty checking optimization does check what has changed in an entity and only triggers an index update if indexed properties are changed. The reason is simple, your interceptor might depend on a non indexed property which would be ignored by this optimization.
(来自 the documentation)
如果不是,请向复制者报告问题,或者至少提及您正在使用的 Hibernate Search/Hibernate ORM 的确切版本:JIRA, test case templates
在我们修复此问题之前(如果它实际上是一个错误),您始终可以显式禁用脏检查优化:
hibernate.search.enable_dirty_check false