/** * Flush search indexes, to be done after a reindex() or reindexAll() operation */ @Autowired public void flushSearchIndexes(ApplicationContext applicationContext) { EntityManagerFactory entityManagerFactory = (EntityManagerFactory) applicationContext.getBean("entityManagerFactory"); FullTextEntityManager fullTextEntityMgr = Search.getFullTextEntityManager(entityManagerFactory.createEntityManager()); fullTextEntityMgr.flushToIndexes(); } }
/** * Regenerates the index for a given class * * @param clazz the class * @param entityManager the entity manager */ public static void reindex(Class clazz, EntityManager entityManager) { FullTextEntityManager txtentityManager = Search.getFullTextEntityManager(entityManager); MassIndexer massIndexer = txtentityManager.createIndexer(clazz); try { massIndexer.startAndWait(); } catch (InterruptedException e) { log.error("mass reindexing interrupted: " + e.getMessage()); } finally { txtentityManager.flushToIndexes(); } }
Logger.getLogger(getClass()).info(" Creating indexes for " + key); fullTextEntityManager.purgeAll(reindexMap.get(key)); fullTextEntityManager.flushToIndexes(); fullTextEntityManager.createIndexer(reindexMap.get(key)) .batchSizeToLoadObjects(100).cacheMode(CacheMode.NORMAL)
public void rollbackedRegister() throws Exception { em.persist( newMember ); resetNewMember(); em.flush(); // force to flush the backend to send the JMS messages into the queue Search.getFullTextEntityManager( em ).flushToIndexes(); throw new RuntimeException( "Shit happens" ); }
/** * Regenerates all the indexed class indexes * * @param async true if the reindexing will be done as a background thread * @param entityManager the entity manager */ public static void reindexAll(boolean async, EntityManager entityManager) { FullTextEntityManager txtentityManager = Search.getFullTextEntityManager(entityManager); MassIndexer massIndexer = txtentityManager.createIndexer(); massIndexer.purgeAllOnStart(true); try { if (!async) { massIndexer.startAndWait(); } else { massIndexer.start(); } } catch (InterruptedException e) { log.error("mass reindexing interrupted: " + e.getMessage()); } finally { txtentityManager.flushToIndexes(); } } }
public void reindex(Class<?> entityClass) { emf.runInTrans((emgr) -> { FullTextEntityManager femg = emgr.getFullTextEntityManager(); femg.purgeAll(entityClass); List<?> allentities = emgr.selectAllAttached(entityClass); for (Object ent : allentities) { femg.index(ent); } femg.flushToIndexes(); // emgr.detach(allentities); return null; }); } }
@After public void tearDown() throws Exception { ftem.getTransaction().begin(); ftem.createQuery( "delete from " + EntityWithIdClass.class.getSimpleName() ).executeUpdate(); ftem.createQuery( "delete from " + EntityWithEmbeddedId.class.getSimpleName() ).executeUpdate(); ftem.purgeAll( EntityWithIdClass.class ); ftem.purgeAll( EntityWithEmbeddedId.class ); ftem.flushToIndexes(); ftem.getTransaction().commit(); ftem.close(); emf.close(); }
@After @Override public void tearDown() { FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager( entityManager ); fullTextEntityManager.purgeAll( Book.class ); fullTextEntityManager.flushToIndexes(); fullTextEntityManager.close(); super.tearDown(); }
@Test public void testIndex() { em.getTransaction().begin(); // verify against index assertEquals( "At the beginning of the test there should be an indexed Bretzel", 1, countBretzelsViaIndex( em ) ); // clear index em.purgeAll( Bretzel.class ); em.flushToIndexes(); // verify Bretzel removed from index assertEquals( "The index should be empty after an purge and flush", 0, countBretzelsViaIndex( em ) ); // re-index manually em.index( em.find( Bretzel.class, bretzel.getId() ) ); em.getTransaction().commit(); assertEquals( "After re-indexing the bretzel should be indexed again", 1, countBretzelsViaIndex( em ) ); }
private void purgeAll(Class<?>... entityTypes) throws Exception { FullTextEntityManager fullTextEm = Search.getFullTextEntityManager( createEntityManager() ); for ( Class<?> entityType : entityTypes ) { fullTextEm.purgeAll( entityType ); fullTextEm.flushToIndexes(); } int numDocs = fullTextEm.getSearchFactory().getIndexReaderAccessor().open( entityTypes ).numDocs(); fullTextEm.close(); assertThat( numDocs ).isEqualTo( 0 ); }
@Test public void testMassIndexer() throws Exception { // verify against index assertEquals( "At the beginning of the test there should be an indexed Bretzel", 1, countBretzelsViaIndex( em ) ); // clear index em.purgeAll( Bretzel.class ); em.flushToIndexes(); // verify Bretzel removed from index assertEquals( "The index should be empty after an purge and flush", 0, countBretzelsViaIndex( em ) ); // re-index em.createIndexer( Bretzel.class ).startAndWait(); assertEquals( "After re-indexing the bretzel should be indexed again", 1, countBretzelsViaIndex( em ) ); }
FullTextEntityManager ftem = Search.getFullTextEntityManager( em ); ftem.purgeAll( Company.class ); ftem.flushToIndexes(); ftem.close();