private void purgeAll(Class<?> entityType, String tenantId) { FullTextSession session = Search.getFullTextSession(openSessionWithTenantId(tenantId)); session.purgeAll(entityType); session.flushToIndexes(); int numDocs = session.getSearchFactory().getIndexReaderAccessor().open(entityType).numDocs(); session.close(); assertThat(numDocs).isEqualTo(0); }
@Override public void tearDown() throws Exception { try { Transaction tx = fts.getTransaction(); if (!tx.isActive()) { tx = fts.beginTransaction(); } assertEquals(1000, fts.createQuery("delete from " + Clock.class.getName()).executeUpdate()); fts.purgeAll(Clock.class); tx.commit(); fts.close(); } finally { super.tearDown(); } }
private void reindex(Class<?> clazz) { log.info("Re-indexing {0}", clazz); ScrollableResults results = null; try { session.purgeAll(clazz); // TODO try this, see how it affects reindexing time: // session.flushToIndexes(); // session.getSearchFactory().optimize(clazz); session.setFlushMode(FlushMode.MANUAL); session.setCacheMode(CacheMode.IGNORE); results = session.createCriteria(clazz).setFetchSize(BATCH_SIZE).scroll(ScrollMode.FORWARD_ONLY); int index = 0; while (results.next()) { objectProgress++; index++; session.index(results.get(0)); // index each element if (index % BATCH_SIZE == 0) { session.flushToIndexes(); // apply changes to indexes session.clear(); // clear since the queue is processed } } session.flushToIndexes(); // apply changes to indexes // TODO try this too, see how it affects reindexing time: // session.getSearchFactory().optimize(clazz); session.clear(); // clear since the queue is processed } catch (Exception e) { log.warn("Unable to index objects of type {0}", e, clazz.getName()); hasError = true; } finally { if (results != null) results.close(); } }
protected void performCleanUp(SessionFactory sf) { log("starting clean up phase"); FullTextSession s = Search.getFullTextSession(sf.openSession()); try { Transaction tx = s.beginTransaction(); s.createSQLQuery("delete from book_author where book_id < :id") .setParameter("id", initialOffset) .executeUpdate(); s.createSQLQuery("delete from book where id < :id") .setParameter("id", initialOffset) .executeUpdate(); s.createSQLQuery("delete from author where id < :id") .setParameter("id", initialOffset) .executeUpdate(); s.purgeAll(Book.class); s.flush(); s.flushToIndexes(); tx.commit(); } finally { s.close(); } }