/** * Clear lucene indexes. * * @throws Exception the exception */ private void clearLuceneIndexes() throws Exception { final Reflections reflections = new Reflections(); for (final Class<?> clazz : reflections .getTypesAnnotatedWith(Indexed.class)) { fullTextEntityManager.purgeAll(clazz); } }
fullTextEntityManager.purgeAll(reindexMap.get(key)); fullTextEntityManager.flushToIndexes(); fullTextEntityManager.createIndexer(reindexMap.get(key))
@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(); }
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 @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 ) ); }
private void doTest(String hql, long expectedTotal, long expectedGoogle) throws InterruptedException, IOException { EntityManager em = emf.createEntityManager(); FullTextEntityManager ftem = Search.getFullTextEntityManager( em ); ftem.purgeAll( Company.class ); ftem.flushToIndexes(); ftem.close();