private void indexClass(Class<?> classToBeIndexed) { StopWatch stopWatch = new StopWatch(); stopWatch.start(); try { getFullTextEntityManager(entityManager) // .createIndexer(classToBeIndexed) // .batchSizeToLoadObjects(batchSizeToLoadObjects) // .threadsToLoadObjects(threadsToLoadObjects) // .threadsForSubsequentFetching(threadsForSubsequentFetching) // .startAndWait(); } catch (InterruptedException e) { log.warn("Interrupted while indexing " + classToBeIndexed.getSimpleName(), e); Thread.currentThread().interrupt(); } finally { stopWatch.stop(); log.info("Indexed {} in {}", classToBeIndexed.getSimpleName(), stopWatch.toString()); } } }
/** * @param clazz */ private long reindexMassIndexer(final Class<?> clazz) { final Session session = sessionFactory.getCurrentSession(); final Criteria criteria = createCriteria(session, clazz, null, true); final Long number = (Long) criteria.uniqueResult(); // Get number of objects to re-index (select count(*) from). log.info("Starting (mass) re-indexing of " + number + " entries of type " + clazz.getName() + "..."); final FullTextSession fullTextSession = Search.getFullTextSession(session); try { fullTextSession.createIndexer(clazz)// .batchSizeToLoadObjects(25) // //.cacheMode(CacheMode.NORMAL) // .threadsToLoadObjects(5) // //.threadsForIndexWriter(1) // .threadsForSubsequentFetching(20) // .startAndWait(); } catch (final InterruptedException ex) { log.error("Exception encountered while reindexing: " + ex.getMessage(), ex); } final SearchFactory searchFactory = fullTextSession.getSearchFactory(); searchFactory.optimize(clazz); log.info("Re-indexing of " + number + " objects of type " + clazz.getName() + " done."); return number; }
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(); } } }
@SuppressWarnings("unchecked") @Test public void testInterceptorWithMassIndexer() throws Exception { setAllBlogEntriesToStatus( BlogStatus.PUBLISHED ); List<Blog> blogEntries = getBlogEntries(); assertEquals( "Wrong total number of entries", 3, blogEntries.size() ); for ( Blog blog : blogEntries ) { assertTrue( blog.getStatus().equals( BlogStatus.PUBLISHED ) ); } Transaction tx = fullTextSession.beginTransaction(); fullTextSession.purgeAll( Blog.class ); fullTextSession.purgeAll( Article.class ); fullTextSession.purgeAll( TotalArticle.class ); tx.commit(); blogEntries = fullTextSession.createFullTextQuery( new MatchAllDocsQuery() ).list(); assertEquals( "Wrong total number of entries. Index should be empty after purge.", 0, blogEntries.size() ); tx = fullTextSession.beginTransaction(); fullTextSession.createIndexer() .batchSizeToLoadObjects( 25 ) .threadsToLoadObjects( 1 ) .threadsForSubsequentFetching( 2 ) .optimizeOnFinish( true ) .startAndWait(); tx.commit(); blogEntries = getBlogEntries(); assertEquals( "Wrong total number of entries.", 3, blogEntries.size() ); }
private void reindexAll() throws InterruptedException { FullTextSession fullTextSession = builder.openFullTextSession(); SilentProgressMonitor progressMonitor = new SilentProgressMonitor(); Assert.assertFalse( progressMonitor.finished ); try { fullTextSession.createIndexer( Object.class ) .threadsForSubsequentFetching( 8 ) .threadsToLoadObjects( 4 ) .batchSizeToLoadObjects( 30 ) .progressMonitor( progressMonitor ) .startAndWait(); } finally { fullTextSession.close(); } Assert.assertTrue( progressMonitor.finished ); }