我想在Hibernate Search中的某处注入我的代码,其中Document对象已完全准备,但尚未编入索引。 据我所知,概念文档对象是由DocumentBuilderIndexedEntity类创建的。方法准备主字段(Id和_hibernate_class),然后调用buildDocumentFields,其中classBridge被调用。然后它添加基准级别的所有字段(也称为FieldBridge),并添加所有embedded objects递归调用buildDocumentFields。到目前为止,我对此很清楚。如何在构建之后但编制索引之前获取org.apache.lucene.document.Document
对于所有桥梁,我逐渐填充Document对象。我的目标是在向索引引擎提供最终文档版本(从getDocument返回女巫)之前进行一些计算。可能吗?什么是最简单的方法呢?
btw。我虽然是关于自定义索引管理器,但它似乎太复杂,这个简单的目的...
感谢您的时间,并希望你的帮助。
解决方案:
我终于决定实施IndexManager实施,扩展DirectoryBasedIndexManager和overrided文件索引方法(performStreamOperation
和performOperations
)。
下面是我的代码:
public class SearchIndexManager extends DirectoryBasedIndexManager
{
private void processDocument(Document doc)
{
if (doc != null && doc.getFields() != null)
{
for (Fieldable field : doc.getFields())
{/*my job goes here*/};
}
}
@Override
public void performStreamOperation
(LuceneWork singleOperation,IndexingMonitor monitor, boolean forceAsync)
{
if (singleOperation != null)
processDocument(singleOperation.getDocument());
super.performStreamOperation(singleOperation, monitor, forceAsync);
}
@Override
public void performOperations
(List<LuceneWork> workList,IndexingMonitor monitor)
{
for (LuceneWork lw: workList)
{
if (lw != null)
processDocument(lw.getDocument());
}
super.performOperations(workList, monitor);
}
}
最后我使用了IndexManager - 请参阅上面的编辑。请让我知道如果我错过了stg,请:) – Saram
这看起来不错!我冒昧地删除了日志语句,因为这些例子并不需要它们,并且不需要初始化方法,所以也删除了它们。 – Sanne
添加了https://hibernate.atlassian.net/browse/HSEARCH-1348,但不确定这是您的预期。 – Saram