本文整理汇总了Java中org.hibernate.search.SearchFactory.optimize方法的典型用法代码示例。如果您正苦于以下问题:Java SearchFactory.optimize方法的具体用法?Java SearchFactory.optimize怎么用?Java SearchFactory.optimize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.search.SearchFactory
的用法示例。
在下文中一共展示了SearchFactory.optimize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reindexMassIndexer
import org.hibernate.search.SearchFactory; //导入方法依赖的package包/类
/**
*
* @param clazz
*/
private long reindexMassIndexer(final Class< ? > clazz)
{
final Session session = getSession();
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;
}
示例2: optimizeIndexes
import org.hibernate.search.SearchFactory; //导入方法依赖的package包/类
/**
* Do real indexes optimization.
*/
public static void optimizeIndexes() throws Exception {
FullTextSession ftSession = null;
Session session = null;
if (optimizeIndexesRunning) {
log.warn("*** Optimize indexes already running ***");
} else {
optimizeIndexesRunning = true;
log.debug("*** Begin optimize indexes ***");
try {
session = HibernateUtil.getSessionFactory().openSession();
ftSession = Search.getFullTextSession(session);
// Optimize indexes
SearchFactory searchFactory = ftSession.getSearchFactory();
searchFactory.optimize();
} catch (Exception e) {
throw e;
} finally {
optimizeIndexesRunning = false;
HibernateUtil.close(ftSession);
HibernateUtil.close(session);
}
log.debug("*** End optimize indexes ***");
}
}