当前位置: 首页>>代码示例>>Java>>正文


Java MassIndexer类代码示例

本文整理汇总了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));
	}
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:26,代码来源:HibernateSearchDaoImpl.java

示例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();
    }
}
 
开发者ID:SMVBE,项目名称:ldadmin,代码行数:23,代码来源:HibernateSearchTools.java

示例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();

}
 
开发者ID:adrianmilne,项目名称:jpa-lucene-spring-demo,代码行数:20,代码来源:BookManagerUnitTest.java

示例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();
    }
}
 
开发者ID:SMVBE,项目名称:ldadmin,代码行数:18,代码来源:HibernateSearchTools.java

示例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;
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:14,代码来源:CommonDaoSupporter.java

示例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();
}
 
开发者ID:krotscheck,项目名称:jersey2-toolkit,代码行数:42,代码来源:SearchIndexContextListenerITest.java

示例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();
}
 
开发者ID:krotscheck,项目名称:jersey2-toolkit,代码行数:43,代码来源:SearchIndexContextListenerITest.java

示例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");
}
 
开发者ID:BandwidthOnDemand,项目名称:bandwidth-on-demand,代码行数:15,代码来源:TextSearchIndexer.java

示例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();
}
 
开发者ID:gg-net,项目名称:dwoss,代码行数:51,代码来源:SearchSingletonBean.java


注:本文中的org.hibernate.search.MassIndexer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。