Search 6 groundwork - Restore support for the massindexer

Description

None

Activity

Show:

Yoann Rodière November 23, 2018 at 3:08 PM

here is the code I wrote during our discussion.

class MassIndexer { // MassIndexer parameters/attributes boolean optimizeBefore = false; boolean purgeBefore = false; boolean optimizeAfter = false; Collection<Class<?>> rootEntityTypes = null; PojoMappingDelegate delegate = null;// = ... MappingWorkExecutor mappingWorkExecutor = delegate.createMappingWorkExecutor(); public void execute() { if ( purgeBefore ) { mappingWorkExecutor.purge( rootEntityTypes ).join(); } if ( optimizeBefore ) { mappingWorkExecutor.optimize( rootEntityTypes ).join(); } // Index // for each IdentifierConsumerDocumentProducer { List<?> entities = ...; indexingMonitor.entitiesLoaded( entities.size() ); SessionContext sessionContext; SessionWorkExecutor sessionWorkExecutor = delegate.createSessionWorkExecutor( sessionContext ); List<CompletableFuture<?>> completableFutures = new ArrayList<>( ); for ( Object entity : entities ) { CompletableFuture<?> entityIndexedFuture = sessionWorkExecutor.add( entity ); completableFutures.add( entityIndexedFuture ); } indexingMonitor.documentBuilt( entities.size() ); CompletableFuture.allOf( completableFutures.toArray( new CompletableFuture[0] ) ) .join(); indexingMonitor.documentAdded( entities.size() ); } mappingWorkExecutor.flush( rootEntityTypes ).join(); if ( optimizeAfter ) { mappingWorkExecutor.optimize( rootEntityTypes ).join(); } } } interface IndexingMonitor { void addToTotalCount(long increment); // Already taken care of void documentsAdded(long increment); // see above void documentsBuilt(int increment); // see above void entitiesLoaded(int increment); // see above void indexingCompleted(); // Already taken care of } interface PojoMappingDelegate { // ... MappingWorkExecutor createMappingWorkExecutor(); SessionWorkExecutor createSessionWorkExecutor(SessionContext ctx); } interface MappingWorkExecutor { CompletableFuture<?> optimize(Collection<Class<?>> types); CompletableFuture<?> purge(Collection<Class<?>> types); CompletableFuture<?> flush(Collection<Class<?>> types); } interface SessionWorkExecutor { CompletableFuture<?> add(Object id, Object entity); CompletableFuture<?> add(Object entity); } class SessionWorkExecutorImpl implements SessionWorkExecutor { Map<Class<?>, IndexWorkExecutor> indexWorkExecutor; CompletableFuture<?> add(Object id, Object entity) { // 1. retrieve and cache the appropriate IndexWorkExecutor (similarly to what we do with PojoTypeWorkPlans in PojoWorkPlan) // 2. add to index // see PojoWorkPlan.add and PojoTypeWorkPlan.add and IndexedEntityWorkPlan.sendWorkToDelegate, in particular, for implementation } } /// BACKEND SPIs // This interface already exists interface IndexManagerImplementor { // ... CompletableFuture<?> optimize(); CompletableFuture<?> purge(); CompletableFuture<?> flush(); IndexWorkExecutor createWorkExecutor(); } interface IndexWorkExecutor { CompletableFuture<?> add(DocumentReferenceProvider documentReferenceProvider, DocumentContributor<D> documentContributor); }

Fabio Massimo Ercoli November 19, 2018 at 9:49 AM
Edited

About the scope, we can say that `MassIndexer` interface will be bounded to `hibernate-search-mapper-orm` module, as in the legacy one it was bounded to `hibernate-search-orm`.
The main change here will be that " the mass indexer will not manipulate documents directly anymore, it will use a `PojoWorkPlan` and pass the entities to that work plan", paying attention on when to trigger reindexing or not.
In a next step we will create a different/dedicated type of work plan.

Fixed

Details

Assignee

Reporter

Sprint

Fix versions

Priority

Created August 27, 2018 at 2:17 PM
Updated January 31, 2019 at 3:08 PM
Resolved December 10, 2018 at 10:48 AM