Hibernate Search のどこかに自分のコードを挿入したいと思います。ここで、Document オブジェクトは完全に準備されていますが、まだインデックスが作成されていません。私の知る限り、コンセプト Document オブジェクトはDocumentBuilderIndexedEntityクラスによって作成されます。getDocumentメソッドは、マスター フィールド (Id および _hibernate_class) を準備し、classBridge が呼び出される buildDocumentFields を呼び出します。次に、すべてのフィールドをベース レベルに追加し (FieldBridge も呼び出します)、再帰的に buildDocumentFieldsを呼び出すすべての埋め込みオブジェクトを追加します。これまでのところ、私にとってはかなり明確です。
すべてのブリッジについて、Document オブジェクトを徐々に埋めていきました。私の目的は、ドキュメントの最終バージョン (ウィッチはgetDocumentから返されます) を取得して、インデックス作成エンジンに提供する前に何らかの計算を行うことです。出来ますか?それを行う最も簡単な方法は何ですか?
ところで。カスタムIndexManagerについて考えましたが、この単純な目的には複雑すぎるようです...
お時間をいただきありがとうございます。お役に立てば幸いです。
解決:
最終的に、 IndexManager の実装、DirectoryBasedIndexManagerの拡張、およびドキュメントのインデックス作成メソッド (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);
}
}