Java Code Examples for org.hibernate.search.FullTextSession#index()
The following examples show how to use
org.hibernate.search.FullTextSession#index() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndexRequestMasterListener.java From development with Apache License 2.0 | 6 votes |
private void handleListIndexing( Collection<? extends DomainObject<?>> list) { Session session = getSession(); if (list == null || session == null) { return; } FullTextSession fts = Search.getFullTextSession(session); Transaction tx = fts.beginTransaction(); for (DomainObject<?> obj : list) { if (obj != null) { fts.index(obj); } } tx.commit(); }
Example 2
Source File: IndexRequestMasterListener.java From development with Apache License 2.0 | 5 votes |
private void handleObjectIndexing(Object parameter) { Session session = getSession(); if (parameter == null || session == null) { return; } FullTextSession fts = Search.getFullTextSession(session); Transaction tx = fts.beginTransaction(); fts.index(parameter); tx.commit(); }
Example 3
Source File: SystemService.java From wallride with Apache License 2.0 | 5 votes |
@Async @Transactional(propagation = Propagation.SUPPORTS) public void reIndex() throws Exception { logger.info("Re-Index started"); FullTextSession fullTextSession = Search.getFullTextSession((entityManager.unwrap(Session.class))); fullTextSession.setFlushMode(FlushMode.MANUAL); fullTextSession.setCacheMode(CacheMode.IGNORE); for (Class persistentClass : fullTextSession.getSearchFactory().getIndexedTypes()) { Transaction transaction = fullTextSession.beginTransaction(); // Scrollable results will avoid loading too many objects in memory ScrollableResults results = fullTextSession.createCriteria(persistentClass) .setFetchSize(BATCH_SIZE) .scroll(ScrollMode.FORWARD_ONLY); int index = 0; while (results.next()) { index++; fullTextSession.index(results.get(0)); //index each element if (index % BATCH_SIZE == 0) { fullTextSession.flushToIndexes(); //apply changes to indexes fullTextSession.clear(); //free memory since the queue is processed } } transaction.commit(); } logger.info("Re-Index finished"); }
Example 4
Source File: HibernateSearchDependentObjectsReindexer.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
private void reindexDependents(final HibernateTemplate hibernateTemplate, final Session session, final BaseDO< ? > obj, final Set<String> alreadyReindexed) { if (alreadyReindexed.contains(getReindexId(obj)) == true) { if (log.isDebugEnabled() == true) { log.debug("Object already re-indexed (skipping): " + getReindexId(obj)); } return; } session.flush(); // Needed to flush the object changes! final FullTextSession fullTextSession = Search.getFullTextSession(session); fullTextSession.setFlushMode(FlushMode.AUTO); fullTextSession.setCacheMode(CacheMode.IGNORE); try { BaseDO< ? > dbObj = (BaseDO< ? >) session.get(obj.getClass(), obj.getId()); if (dbObj == null) { dbObj = (BaseDO< ? >) session.load(obj.getClass(), obj.getId()); } fullTextSession.index(dbObj); alreadyReindexed.add(getReindexId(dbObj)); if (log.isDebugEnabled() == true) { log.debug("Object added to index: " + getReindexId(dbObj)); } } catch (final Exception ex) { // Don't fail if any exception while re-indexing occurs. log.info("Fail to re-index " + obj.getClass() + ": " + ex.getMessage()); } // session.flush(); // clear every batchSize since the queue is processed final List<Entry> entryList = map.get(obj.getClass()); reindexDependents(hibernateTemplate, session, obj, entryList, alreadyReindexed); }
Example 5
Source File: IndexHelper.java From document-management-system with GNU General Public License v2.0 | 4 votes |
protected int doRebuildIndex() throws Exception { FullTextSession fullTextSession = (FullTextSession) entityManager.getDelegate(); fullTextSession.setFlushMode(org.hibernate.FlushMode.MANUAL); fullTextSession.setCacheMode(org.hibernate.CacheMode.IGNORE); fullTextSession.purgeAll(NodeDocumentVersion.class); fullTextSession.getSearchFactory().optimize(NodeDocumentVersion.class); String query = "select ndv from NodeDocumentVersion ndv"; ScrollableResults cursor = fullTextSession.createQuery(query).scroll(); cursor.last(); int count = cursor.getRowNumber() + 1; log.warn("Re-building Wine index for " + count + " objects."); if (count > 0) { int batchSize = 300; cursor.first(); // Reset to first result row int i = 0; while (true) { fullTextSession.index(cursor.get(0)); if (++i % batchSize == 0) { fullTextSession.flushToIndexes(); fullTextSession.clear(); // Clear persistence context for each batch log.info("Flushed index update " + i + " from Thread " + Thread.currentThread().getName()); } if (cursor.isLast()) { break; } cursor.next(); } } cursor.close(); fullTextSession.flushToIndexes(); fullTextSession.clear(); // Clear persistence context for each batch fullTextSession.getSearchFactory().optimize(NodeDocumentVersion.class); return count; }