我是休眠搜索的新手,我需要将它与我的应用程序数据库一起使用。我有几个索引实体类,我想根据它们的状态从索引中排除一些实体。在我的情况下,我想用 template == null 排除对象我找到了这个功能 并实现了它,但是这个拦截器不起作用\调用
这就是我所拥有的
public class WorkDocumentInterceptor implements EntityIndexingInterceptor<WorkDocument> {
@Override
public IndexingOverride onAdd(WorkDocument workDocument) {
System.out.println("on ADD workDocument = " + workDocument.getId());
if (workDocument.getTemplate() == null) {
System.out.println("SKIP DOCUMENT " + workDocument.getId() + ":" + workDocument.getTitle());
return IndexingOverride.SKIP;
}
return IndexingOverride.APPLY_DEFAULT;
}
@Override
public IndexingOverride onUpdate(WorkDocument workDocument) {
if (workDocument.getTemplate() == null) {
return IndexingOverride.REMOVE;
}
return IndexingOverride.UPDATE;
}
@Override
public IndexingOverride onDelete(WorkDocument workDocument) {
return IndexingOverride.APPLY_DEFAULT;
}
@Override
public IndexingOverride onCollectionUpdate(WorkDocument workDocument) {
return onUpdate(workDocument);
}
}
实体类
@Entity
@Table(name = "work_document")
@Indexed(interceptor = WorkDocumentInterceptor.class)
public class WorkDocument implements Serializable {
@Id
@Basic(optional = false)
@Column(name = "id")
private Long id;
Template template;
...
}
当索引运行时,我什至看不到这个输出,似乎拦截器没有调用
System.out.println("on ADD workDocument = " + workDocument.getId());
要重建索引,我称之为
em.createIndexer(clazz)
.purgeAllOnStart(true)
.optimizeAfterPurge(true)
.optimizeOnFinish(true)
.batchSizeToLoadObjects(25)
.cacheMode(CacheMode.IGNORE)
.threadsToLoadObjects(5)
.threadsForIndexWriter(3)
.threadsForSubsequentFetching(20)
.startAndWait();
为什么它不起作用?谢谢。