private SearchIntegrator createSearchIntegrator(IndexingConfiguration indexingConfiguration, ComponentRegistry cr, ClassLoader aggregatedClassLoader) { SearchIntegrator searchIntegrator = cr.getComponent(SearchIntegrator.class); if (searchIntegrator != null && !searchIntegrator.isStopped()) { // a paranoid check against an unlikely failure throw new IllegalStateException("SearchIntegrator already initialized!"); } // load ProgrammaticSearchMappingProviders from classpath Collection<ProgrammaticSearchMappingProvider> programmaticSearchMappingProviders = new LinkedHashSet<>(); programmaticSearchMappingProviders.add(new DefaultSearchMappingProvider()); // make sure our DefaultSearchMappingProvider is first programmaticSearchMappingProviders.addAll(ServiceFinder.load(ProgrammaticSearchMappingProvider.class, aggregatedClassLoader)); // load LuceneAnalysisDefinitionProvider from classpath Collection<LuceneAnalysisDefinitionProvider> analyzerDefProviders = ServiceFinder.load(LuceneAnalysisDefinitionProvider.class, aggregatedClassLoader); // Set up the search factory for Hibernate Search first. SearchConfiguration config = new SearchableCacheConfiguration(indexingConfiguration.indexedEntities(), indexingConfiguration.properties(), programmaticSearchMappingProviders, analyzerDefProviders, cr, aggregatedClassLoader); searchIntegrator = new SearchIntegratorBuilder().configuration(config).buildSearchIntegrator(); cr.registerComponent(searchIntegrator, SearchIntegrator.class); return searchIntegrator; }
public void testCorrectShutdown() { CacheContainer cc = null; try { ConfigurationBuilder cfg = new ConfigurationBuilder(); cfg .transaction() .transactionMode(TransactionMode.TRANSACTIONAL) .indexing() .index(Index.ALL) .addIndexedEntity(Person.class) .addProperty("default.directory_provider", "local-heap") .addProperty("lucene_version", "LUCENE_CURRENT"); cc = TestCacheManagerFactory.createCacheManager(cfg); Cache<?, ?> cache = cc.getCache(); SearchIntegrator sfi = TestingUtil.extractComponent(cache, SearchIntegrator.class); assert ! sfi.isStopped(); cc.stop(); assert sfi.isStopped(); } finally { // proper cleanup for exceptional execution TestingUtil.killCacheManagers(cc); } }
public void testPersistence() throws PersistenceException, ParseException { verifyFullTextHasMatches(0); Country italy = new Country(); italy.countryName = "Italy"; City rome = new City(); rome.name = "Rome"; italy.cities.add(rome); cache.put("IT", italy); assert ! store.contains("IT"); verifyFullTextHasMatches(1); cache.evict("IT"); assert store.contains("IT"); InternalCacheEntry internalCacheEntry = cache.getAdvancedCache().getDataContainer().get("IT"); assert internalCacheEntry==null; verifyFullTextHasMatches(1); Country country = cache.get("IT"); assert country != null; assert "Italy".equals(country.countryName); verifyFullTextHasMatches(1); cache.stop(); assert search.unwrap(SearchIntegrator.class).isStopped(); TestingUtil.killCacheManagers(cm); // Now let's check the entry is not re-indexed during data preloading: recreateCacheManager(); // People should generally use a persistent index; we use RAMDirectory for // test cleanup, so for our configuration it needs now to contain zero // matches: on filesystem it would be exactly one as expected (two when ISPN-1179 was open) verifyFullTextHasMatches(0); }