fullTextEntityManager.flushToIndexes(); fullTextEntityManager.createIndexer(reindexMap.get(key)) .batchSizeToLoadObjects(100).cacheMode(CacheMode.NORMAL) .threadsToLoadObjects(4).startAndWait();
@Override public void index(String entity) { Class<?> clazz = getEntityClass( entity ); try ( Session session = hibernateSessionFactory.openSession() ) { FullTextSession fulltextSession = Search.getFullTextSession( session ); fulltextSession.createIndexer( clazz ) .batchSizeToLoadObjects( batchSize ) .cacheMode( CacheMode.NORMAL ) .threadsToLoadObjects( numberOfObjectLoadingThreads ) .startAndWait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new SearchException( "Unable to complete indexing" ); } }
@POST @Path("/reindex") public Response reindex(@QueryParam("limit") Long limit) { FullTextEntityManager fullTextEm = Search.getFullTextEntityManager( em ); MassIndexer indexer = fullTextEm.createIndexer( Page.class, User.class ) .purgeAllOnStart( true ) .typesToIndexInParallel( 2 ) .batchSizeToLoadObjects( 25 ) .idFetchSize( 150 ) .threadsToLoadObjects( 10 ) .cacheMode( CacheMode.IGNORE ); // Cache is likely to do more harm than good in our case (very few relations) if ( limit != null ) { indexer.limitIndexedObjectsTo( limit ); } indexer.start(); return Response.accepted().build(); }
private static void populateIndexes(final SessionFactoryImplementor sessionFactory, final int nbOfThreadLoad, final int nbOfThreadFetching) throws InterruptedException { FullTextSession fullTextSession = null; try { final Session session = sessionFactory.openSession(); fullTextSession = Search.getFullTextSession(session); final Transaction tx = fullTextSession.beginTransaction(); final MassIndexer indexer = fullTextSession.createIndexer(); indexer.batchSizeToLoadObjects(25).cacheMode(CacheMode.NORMAL).optimizeOnFinish(true); indexer.threadsToLoadObjects(nbOfThreadLoad).threadsForSubsequentFetching(nbOfThreadFetching).startAndWait(); fullTextSession.createIndexer(); tx.commit(); } finally { if (fullTextSession != null) { fullTextSession.close(); } } }
@TransactionAttribute(TransactionAttributeType.NEVER) public void indexConcerts() { try { Search.getFullTextEntityManager( entityManager ) .createIndexer() .batchSizeToLoadObjects( 1 ) .threadsToLoadObjects( 1 ) .transactionTimeout( 10 ) .cacheMode( CacheMode.IGNORE ) .startAndWait(); } catch (InterruptedException e) { throw new RuntimeException( e ); } } }
public boolean rebuildIndex() throws InterruptedException { FullTextEntityManager fullTextEntityManager = Search .getFullTextEntityManager( entityManager ); try { fullTextEntityManager .createIndexer() .batchSizeToLoadObjects( 30 ) .threadsToLoadObjects( 4 ) .cacheMode( CacheMode.NORMAL ) .startAndWait(); } catch (Exception e) { return false; } return true; }