本文整理汇总了Java中org.hibernate.search.MassIndexer类的典型用法代码示例。如果您正苦于以下问题:Java MassIndexer类的具体用法?Java MassIndexer怎么用?Java MassIndexer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MassIndexer类属于org.hibernate.search包,在下文中一共展示了MassIndexer类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reindexClasses
import org.hibernate.search.MassIndexer; //导入依赖的package包/类
protected void reindexClasses(FullTextEntityManager fullTextEntityManager, Set<Class<?>> entityClasses)
throws InterruptedException {
int batchSize = propertyService.get(HIBERNATE_SEARCH_REINDEX_BATCH_SIZE);
int loadThreads = propertyService.get(HIBERNATE_SEARCH_REINDEX_LOAD_THREADS);
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Targets for indexing job: {}", entityClasses);
}
for (Class<?> clazz : entityClasses) {
ProgressMonitor progressMonitor = new ProgressMonitor();
Thread t = new Thread(progressMonitor);
LOGGER.info(String.format("Reindexing %1$s.", clazz));
t.start();
MassIndexer indexer = fullTextEntityManager.createIndexer(clazz);
indexer.batchSizeToLoadObjects(batchSize)
.threadsToLoadObjects(loadThreads)
.cacheMode(CacheMode.NORMAL)
.progressMonitor(progressMonitor)
.startAndWait();
progressMonitor.stop();
t.interrupt();
LOGGER.info(String.format("Reindexing %1$s done.", clazz));
}
}
示例2: reindexAll
import org.hibernate.search.MassIndexer; //导入依赖的package包/类
/**
* Regenerates all the indexed class indexes
*
* @param async true if the reindexing will be done as a background thread
* @param sess the hibernate session
*/
public static void reindexAll(boolean async, Session sess) {
FullTextSession txtSession = Search.getFullTextSession(sess);
MassIndexer massIndexer = txtSession.createIndexer();
massIndexer.purgeAllOnStart(true);
try {
if (!async) {
massIndexer.startAndWait();
} else {
massIndexer.start();
}
} catch (InterruptedException e) {
log.error("mass reindexing interrupted: " + e.getMessage());
} finally {
txtSession.flushToIndexes();
}
}
示例3: testUpdateIndex
import org.hibernate.search.MassIndexer; //导入依赖的package包/类
@Test
public void testUpdateIndex(@Mocked(methods = "getFullTextEntityManager")
final BookManager mockManager, @Mocked
final FullTextEntityManager mockFullTextEntityManager, @Mocked
final MassIndexer mockIndexer) throws Exception {
new Expectations() {
{
mockManager.getFullTextEntityManager();
result = mockFullTextEntityManager;
mockFullTextEntityManager.createIndexer();
result = mockIndexer;
mockIndexer.startAndWait();
}
};
bookManager.updateFullTextIndex();
}
示例4: reindex
import org.hibernate.search.MassIndexer; //导入依赖的package包/类
/**
* Regenerates the index for a given class
*
* @param clazz the class
* @param sess the hibernate session
*/
public static void reindex(Class clazz, Session sess) {
FullTextSession txtSession = Search.getFullTextSession(sess);
MassIndexer massIndexer = txtSession.createIndexer(clazz);
try {
massIndexer.startAndWait();
} catch (InterruptedException e) {
log.error("mass reindexing interrupted: " + e.getMessage());
} finally {
txtSession.flushToIndexes();
}
}
示例5: reindex
import org.hibernate.search.MassIndexer; //导入依赖的package包/类
protected boolean reindex(Session session, Class<?> entityClass) {
boolean result = false;
try {
LOGGER.info("reindex: [" + entityClass.getSimpleName() + "]");
FullTextSession fullTextSession = getFullTextSession(session);
MassIndexer massIndexer = fullTextSession.createIndexer(entityClass);
massIndexer.startAndWait();
result = true;
} catch (Exception ex) {
throw new CommonDaoException(ex);
}
return result;
}
示例6: testOnStartup
import org.hibernate.search.MassIndexer; //导入依赖的package包/类
/**
* Assert that the index is created on startup.
*
* @throws Exception Any unexpected exceptions.
*/
@Test
@PrepareForTest({Search.class, SearchIndexContextListener.class})
public void testOnStartup() throws Exception {
// Set up a fake session factory
SessionFactory mockFactory = mock(SessionFactory.class);
Session mockSession = mock(Session.class);
when(mockFactory.openSession()).thenReturn(mockSession);
// Set up a fake indexer
MassIndexer mockIndexer = mock(MassIndexer.class);
// Set up our fulltext session.
FullTextSession mockFtSession = mock(FullTextSession.class);
when(mockFtSession.createIndexer())
.thenReturn(mockIndexer);
// This is the way to tell PowerMock to mock all static methods of a
// given class
mockStatic(Search.class);
when(Search.getFullTextSession(mockSession))
.thenReturn(mockFtSession);
SearchIndexContextListener listener =
mock(SearchIndexContextListener.class);
doReturn(mockFactory).when(listener).createSessionFactory();
doCallRealMethod().when(listener).contextInitialized(any());
// Run the test
listener.contextInitialized(mock(ServletContextEvent.class));
verify(mockIndexer).startAndWait();
// Verify that the session was closed.
verify(mockSession).close();
}
示例7: testInterruptedIndex
import org.hibernate.search.MassIndexer; //导入依赖的package包/类
/**
* Assert that an interrupted exception exits cleanly.
*
* @throws Exception An exception that might be thrown.
*/
@Test
@PrepareForTest({Search.class, SearchIndexContextListener.class})
public void testInterruptedIndex() throws Exception {
// Set up a fake session factory
SessionFactory mockFactory = mock(SessionFactory.class);
Session mockSession = mock(Session.class);
when(mockFactory.openSession()).thenReturn(mockSession);
// Set up a fake indexer
MassIndexer mockIndexer = mock(MassIndexer.class);
// Set up our fulltext session.
FullTextSession mockFtSession = mock(FullTextSession.class);
when(mockFtSession.createIndexer())
.thenReturn(mockIndexer);
doThrow(new InterruptedException())
.when(mockIndexer)
.startAndWait();
// This is the way to tell PowerMock to mock all static methods of a
// given class
mockStatic(Search.class);
when(Search.getFullTextSession(mockSession))
.thenReturn(mockFtSession);
SearchIndexContextListener listener =
mock(SearchIndexContextListener.class);
doReturn(mockFactory).when(listener).createSessionFactory();
doCallRealMethod().when(listener).contextInitialized(any());
// Run the test
listener.contextInitialized(mock(ServletContextEvent.class));
// Verify that the session was closed.
verify(mockSession).close();
verify(mockFactory).close();
}
示例8: indexDatabaseContent
import org.hibernate.search.MassIndexer; //导入依赖的package包/类
public void indexDatabaseContent() {
final FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
final MassIndexerProgressMonitor indexMonitor = new SimpleIndexingProgressMonitor(10);
try {
final MassIndexer indexer = fullTextEntityManager.createIndexer();
indexer.threadsToLoadObjects(1);
indexer.progressMonitor(indexMonitor);
indexer.startAndWait();
} catch (InterruptedException e) {
logger.error("Error indexing current database content", e);
}
logger.info("Succesfully indexed database content for full text search");
}
示例9: reindexSearch
import org.hibernate.search.MassIndexer; //导入依赖的package包/类
@Schedule(hour = "2")
@Override
public void reindexSearch() {
active = true;
final SubMonitor m = monitorFactory.newSubMonitor("Recreationg Searchindex");
m.start();
try {
MassIndexer indexer = Search.getFullTextEntityManager(em).createIndexer();
indexer.progressMonitor(new SimpleIndexingProgressMonitor() {
private final AtomicLong documentsDoneCounter = new AtomicLong();
private final AtomicLong totalCounter = new AtomicLong();
private final AtomicLong entitiesLoaded = new AtomicLong();
@Override
public void entitiesLoaded(int size) {
entitiesLoaded.set(size);
}
@Override
public void addToTotalCount(long count) {
super.addToTotalCount(count);
totalCounter.addAndGet(count);
}
@Override
public void documentsAdded(long increment) {
super.documentsAdded(increment);
long current = documentsDoneCounter.addAndGet(increment);
if ( current % getStatusMessagePeriod() == 0 ) {
m.message("Prozess " + current + "/" + totalCounter.get()
+ " | Entities loaded: " + entitiesLoaded.get());
}
}
});
// Values still not optimal, but the mysql db holds.
indexer
.batchSizeToLoadObjects(10000)
.threadsToLoadObjects(3)
.startAndWait();
} catch (InterruptedException ex) {
LOG.error("Error on Reindex Search.", ex);
} finally {
active = false;
}
m.finish();
}