hibernate - How to get org.apache.lucene.document.Document after build but before indexing -
i'd inject code somewhere in hibernate search, document object prepared not indexed yet. far know, concept document object created documentbuilderindexedentity class. getdocument method prepares master fields (id , _hibernate_class) , calls builddocumentfields, classbridge called. adds fields on base level (also calling fieldbridge) , adds embedded objects calling recursively builddocumentfields. far rather clear me.
for bridges got progressively filled document object. aim final document version (witch returned getdocument) made computing before provided indexing engine. possible? simplest way it?
btw. though custom indexmanager, seems complex simple purpose...
thanks time , hope help.
solution:
i decided implement indexmanager implementation, extended directorybasedindexmanager , overrided document indexing methods (performstreamoperation
, performoperations
).
below code:
public class searchindexmanager extends directorybasedindexmanager { private void processdocument(document doc) { if (doc != null && doc.getfields() != null) { (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) { (lucenework lw: worklist) { if (lw != null) processdocument(lw.getdocument()); } super.performoperations(worklist, monitor); } }
with versions available today (4.2) not possible: apply classbridge edit document, in alternative other fields.
i love add such feature , think we'll redesign classbridge annotation applied in late phase (after document construction) allow during works support lucene 4.
please describe expect on jira feature request; invite propose patch in case we're having many changes in mind think it's best if exemplify use case, ideally test. pseudo-code test welcome too, since it's concept idea.
to avoid waiting future release can indeed use custom indexmanager: it's not complex provided ones designed extended, override methods need. alternatively indexmanager consider implementing custom org.hibernate.search.backend.spi.backendqueueprocessor extending default 1 (org.hibernate.search.backend.impl.lucene.lucenebackendqueueprocessor). keep in mind don't keep backwards compatibility policy these types other apis.
Comments
Post a Comment