@Async public void reindexAll(int batchSize) { LOGGER.info("Start creating search index."); if(batchSize <= 0) { batchSize = DEFAULT_BATCH_INDEX_SIZE; } try { FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager); fullTextEntityManager.createIndexer(INDEX_DOMAIN_CLASSES.toArray(new Class[0])) .typesToIndexInParallel(INDEX_DOMAIN_CLASSES.size()) .batchSizeToLoadObjects(batchSize) .threadsToLoadObjects(5) .idFetchSize(150) .startAndWait(); LOGGER.info("Successfully created search index."); } catch (InterruptedException e) { LOGGER.warn("An error occurred trying to build the search index: {}", e.toString()); } } }
@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(); }
@Test @RequiresDialect(comment = "MySQL definitely should accept Integer.MIN_VALUE", strictMatching = false, value = org.hibernate.dialect.MySQLDialect.class) public void testSetFetchSizeOnMySQL() throws InterruptedException { SearchIntegrator searchIntegrator = getExtendedSearchIntegrator(); MockErrorHandler mockErrorHandler = MassIndexerErrorReportingTest.getErrorHandler( searchIntegrator ); FullTextSession fullTextSession = MassIndexerErrorReportingTest.prepareSomeData( this ); fullTextSession.createIndexer( Book.class ).idFetchSize( Integer.MIN_VALUE ).startAndWait(); getSession().close(); String errorMessage = mockErrorHandler.getErrorMessage(); Assert.assertEquals( null, errorMessage ); }
@Test @RequiresDialect(comment = "H2 does not accept negative fetch sizes", strictMatching = true, value = org.hibernate.dialect.H2Dialect.class) public void testSetFetchSizeOnH2Fails() throws InterruptedException { SearchIntegrator searchIntegrator = getExtendedSearchIntegrator(); MockErrorHandler mockErrorHandler = MassIndexerErrorReportingTest.getErrorHandler( searchIntegrator ); FullTextSession fullTextSession = MassIndexerErrorReportingTest.prepareSomeData( this ); fullTextSession.createIndexer( Book.class ).idFetchSize( -1 ).startAndWait(); getSession().close(); String errorMessage = mockErrorHandler.getErrorMessage(); Assert.assertEquals( "HSEARCH000211: An exception occurred while the MassIndexer was fetching the primary identifiers list", errorMessage ); Throwable exception = mockErrorHandler.getLastException(); Assert.assertTrue( exception instanceof org.hibernate.exception.GenericJDBCException ); }