/** * @see ContextDAO#updateSearchIndexAsync() */ @Override public Future<?> updateSearchIndexAsync() { try { log.info("Started asynchronously updating the search index..."); return Search.getFullTextSession(sessionFactory.getCurrentSession()).createIndexer().start(); } catch (Exception e) { throw new RuntimeException("Failed to start asynchronous search index update", e); } }
/** * @return future */ public Future<?> reCreateIndex() { FullTextSession fullTextSession = getFullTextSession(); return fullTextSession.createIndexer().start(); }
/** * @return future */ public Future<?> reCreateIndex() { FullTextSession fullTextSession = getFullTextSession(); return fullTextSession.createIndexer().start(); }
/** * @see ContextDAO#updateSearchIndex() */ @Override public void updateSearchIndex() { try { log.info("Updating the search index... It may take a few minutes."); Search.getFullTextSession(sessionFactory.getCurrentSession()).createIndexer().startAndWait(); GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject( OpenmrsConstants.GP_SEARCH_INDEX_VERSION); if (gp == null) { gp = new GlobalProperty(OpenmrsConstants.GP_SEARCH_INDEX_VERSION); } gp.setPropertyValue(OpenmrsConstants.SEARCH_INDEX_VERSION.toString()); Context.getAdministrationService().saveGlobalProperty(gp); log.info("Finished updating the search index"); } catch (Exception e) { throw new RuntimeException("Failed to update the search index", e); } }
/** * {@inheritDoc} */ @Override public void rebuildIndex() { getFullTextSession().createIndexer(Topic.class).start(); } }
@Override protected void execute(FullTextSession fts) { try { fts.createIndexer( Book.class ).startAndWait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException( e ); } } }
@Test public void testCreationOfTheDefaultMassIndexer() throws Exception { FullTextSession fullTextSession = builder.openFullTextSession(); MassIndexer indexer = fullTextSession.createIndexer( Object.class ); assertThat( indexer, instanceOf( MassIndexerImpl.class ) ); }
@Test public void testCreationOfTheSelectedMassIndexer() throws Exception { Session session = openSession(); FullTextSession fullTextSession = Search.getFullTextSession( session ); MassIndexer indexer = fullTextSession.createIndexer( Clock.class ); assertThat( indexer, instanceOf( NoopMassIndexer.class ) ); }
@Test public void testBatchIndexing() throws Exception { SessionFactory sessionFactory = (SessionFactory) bundleContext.getService( serviceReference ); FullTextSession fullTextSession = Search.getFullTextSession( sessionFactory.openSession() ); AssertingMassIndexerProgressMonitor progressMonitor = new AssertingMassIndexerProgressMonitor( 0 ); fullTextSession.createIndexer( Muppet.class ).progressMonitor( progressMonitor ).startAndWait(); progressMonitor.assertExpectedProgressMade(); persistElmo( fullTextSession ); progressMonitor = new AssertingMassIndexerProgressMonitor( 1 ); fullTextSession.createIndexer( Muppet.class ).progressMonitor( progressMonitor ).startAndWait(); progressMonitor.assertExpectedProgressMade(); }
@Test public void testFactoryCanReadConfiguration() throws Exception { Session session = openSession(); FullTextSession fullTextSession = Search.getFullTextSession( session ); NoopMassIndexer indexer = (NoopMassIndexer) fullTextSession.createIndexer( Clock.class ); assertTrue( "The factory cannot read the configuration properties", indexer.isConfigurationReadable() ); }
private void massIndexFooInstances(MassIndexerProgressMonitor monitor) throws InterruptedException { FullTextSession fullTextSession = Search.getFullTextSession( openSession() ); MassIndexer massIndexer = fullTextSession.createIndexer( Foo.class ); massIndexer.progressMonitor( monitor ); massIndexer.startAndWait(); fullTextSession.close(); }
@Test public void testIndexUpdatesViaMassIndexerProhibitedByInterceptor() throws Exception { indexTestData(); MassIndexer massIndexer = fullTextSession.createIndexer(); massIndexer.startAndWait(); FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( new MatchAllDocsQuery() ); assertEquals( "There should be no indexed entities, since interceptor also applied for mass indexer", 0, fullTextQuery.list().size() ); }
private void rebuildIndexWithMassIndexer(Class<?> entityType, String tenantId) throws Exception { FullTextSession session = Search.getFullTextSession( openSessionWithTenantId( tenantId ) ); session.createIndexer( entityType ).purgeAllOnStart( true ).startAndWait(); session.close(); String indexName = getExtendedSearchIntegrator().getIndexBindings().get( entityType ) .getIndexManagerSelector().all().iterator().next().getIndexName(); assertThat( getNumberOfDocumentsInIndexByQuery( indexName, DocumentBuilderIndexedEntity.TENANT_ID_FIELDNAME, tenantId ) ).isGreaterThan( 0 ); }
@Test public void testReindexedOnce() throws InterruptedException { Assert.assertEquals( 2, countBooksInIndex() ); Session session = openSession(); FullTextSession fullTextSession = Search.getFullTextSession( session ); MassIndexer massIndexer = fullTextSession.createIndexer(); massIndexer.startAndWait(); session.close(); Assert.assertEquals( 2, countBooksInIndex() ); }
@Test public void testFieldBridgeOnLazyFieldReindexTest() throws InterruptedException { prepareEntities(); verifyMatchExistsWithName( "name", "name" ); try ( Session session = openSession() ) { FullTextSession fullTextSession = Search.getFullTextSession( session ); MassIndexer massIndexer = fullTextSession.createIndexer( Root.class ); massIndexer.startAndWait(); } verifyMatchExistsWithName( "name", "name" ); }
@Test @RequiresDialect(comment = "MySQL definitely should accept Integer.MIN_VALUE", strictMatching = false, value = org.hibernate.dialect.MySQLDialect.class) public void testSetFetchSizeOnMySQL() throws InterruptedException { SearchIntegrator searchIntegrator = getExtendedSearchIntegrator(); MockErrorHandler mockErrorHandler = MassIndexerErrorReportingTest.getErrorHandler( searchIntegrator ); FullTextSession fullTextSession = MassIndexerErrorReportingTest.prepareSomeData( this ); fullTextSession.createIndexer( Book.class ).idFetchSize( Integer.MIN_VALUE ).startAndWait(); getSession().close(); String errorMessage = mockErrorHandler.getErrorMessage(); Assert.assertEquals( null, errorMessage ); }
@Test public void testLazyIndirectCollectionBridgeReindex() throws InterruptedException { prepareEntities(); verifyMatchExistsWithName( "name", "name" ); try ( Session session = openSession() ) { FullTextSession fullTextSession = Search.getFullTextSession( session ); MassIndexer massIndexer = fullTextSession.createIndexer( Root.class ); massIndexer.startAndWait(); } verifyMatchExistsWithName( "name", "name" ); }
@Test public void testAllRelevantProgressMonitoringOperationsCalled() throws InterruptedException { // let mass indexer re-index the data in the db (created in initializeData()) AssertingMassIndexerProgressMonitor monitor = new AssertingMassIndexerProgressMonitor( 10, 10 ); fullTextSession.createIndexer( LegacyCar.class ) .progressMonitor( monitor ) .startAndWait(); fullTextSession.createFullTextQuery( new MatchAllDocsQuery(), LegacyCar.class ) .getResultSize(); monitor.assertExpectedProgressMade(); }
@Test public void testReindexingWithCompositeIds() throws InterruptedException { try ( FullTextSession fullTextSession = ftsBuilder.openFullTextSession() ) { storeTestData( fullTextSession ); } try ( FullTextSession fullTextSession = ftsBuilder.openFullTextSession() ) { fullTextSession.createIndexer().startAndWait(); } SearchFactory searchFactory = ftsBuilder.getSearchFactory(); SearchIntegrator searchIntegrator = searchFactory.unwrap( SearchIntegrator.class ); CountingErrorHandler errorHandler = (CountingErrorHandler) searchIntegrator.getErrorHandler(); assertEquals( 0, errorHandler.getTotalCount() ); }
@Test public void testMassIndexerWithProxyTest() throws InterruptedException { prepareEntities(); verifyMatchExistsWithName( "lazyEntity.name", TEST_NAME_CONTENT ); verifyMatchExistsWithName( "lazyEntity2.name", TEST_NAME_CONTENT ); FullTextSession fullTextSession = Search.getFullTextSession( openSession() ); MassIndexer massIndexer = fullTextSession.createIndexer( IndexedEmbeddedProxyRootEntity.class ); massIndexer.startAndWait(); fullTextSession.close(); verifyMatchExistsWithName( "lazyEntity.name", TEST_NAME_CONTENT ); verifyMatchExistsWithName( "lazyEntity2.name", TEST_NAME_CONTENT ); }