protected SearchManagerImplementor getSearchManager() { if (!isIndexed) { throw new IllegalStateException("Cache is not indexed"); } if (searchManager == null) { searchManager = SecurityActions.getCacheSearchManager(cache).unwrap(SearchManagerImplementor.class); } return searchManager; }
protected SearchIntegrator getSearchFactory() { if (searchFactory == null) { searchFactory = getSearchManager().unwrap(SearchIntegrator.class); } return searchFactory; }
private boolean isMasterNode(Cache<?,?> cache) { //Implicitly verifies the components are setup as configured by casting: SearchManager searchManager = Search.getSearchManager(cache); SearchIntegrator searchFactory = searchManager.unwrap(SearchIntegrator.class); InfinispanIndexManager indexManager = (InfinispanIndexManager) searchFactory.getIndexManager("person"); return indexManager.isMasterLocal(); }
@Test public void testIndexAndQuery() throws Exception { SearchManager searchManager = Search.getSearchManager(cache); cache.put(123405, new Bond(new Date(System.currentTimeMillis()), 450L)); assertEfficientIndexingUsed(searchManager.unwrap(SearchIntegrator.class), Bond.class); cache.put(123502, new Debenture("GB", 116d)); assertEfficientIndexingUsed(searchManager.unwrap(SearchIntegrator.class), Debenture.class); cache.put(223456, new Bond(new Date(System.currentTimeMillis()), 550L)); assertEfficientIndexingUsed(searchManager.unwrap(SearchIntegrator.class), Bond.class); CacheQuery<?> query = searchManager.getQuery(new MatchAllDocsQuery(), Bond.class, Debenture.class); assertEquals(query.list().size(), 3); CacheQuery<?> queryBond = searchManager.getQuery(new MatchAllDocsQuery(), Bond.class); assertEquals(queryBond.getResultSize(), 2); CacheQuery<?> queryDeb = searchManager.getQuery(new MatchAllDocsQuery(), Debenture.class); assertEquals(queryDeb.getResultSize(), 1); }
private SearchIntegrator extractSearchFactoryImplementor(EmbeddedCacheManager embeddedCacheManager) { Cache<Object, Object> cache = embeddedCacheManager.getCache("Indexed"); cache.put("hey this type exists", new Person("id", "name", 3)); SearchManager searchManager = Search.getSearchManager(cache); return searchManager.unwrap(SearchIntegrator.class); }
/** * This is invoked only on the receiving node, before {@link #perform(org.infinispan.context.InvocationContext)}. */ @Override public void fetchExecutionContext(CommandInitializer ci) { String name = cacheName.toString(); if (ci.getCacheManager().cacheExists(name)) { Cache cache = ci.getCacheManager().getCache(name); SearchManager searchManager = new SearchManagerImpl(cache.getAdvancedCache()); searchFactory = searchManager.unwrap(SearchIntegrator.class); queryInterceptor = ComponentRegistryUtils.getQueryInterceptor(cache); } else { throw new CacheException("Cache named '" + name + "' does not exist on this CacheManager, or was not started"); } }
public static StaticTestingErrorHandler extract(Cache cache) { SearchManager searchManager = Search.getSearchManager(cache); SearchIntegrator searchFactory = searchManager.unwrap(SearchIntegrator.class); ErrorHandler errorHandler = searchFactory.getErrorHandler(); assertNotNull(errorHandler); if (errorHandler instanceof WrappingErrorHandler) { errorHandler = ((WrappingErrorHandler) errorHandler).unwrap(); } assertTrue(errorHandler instanceof StaticTestingErrorHandler); return (StaticTestingErrorHandler) errorHandler; }
protected int queryIndex(Cache<?, ?> cache, String query) throws ParseException { QueryParser qp = createQueryParser("blurb"); Query q = qp.parse(query); HSQuery hsQuery = Search.getSearchManager(cache).unwrap(SearchIntegrator.class).createHSQuery(q, Person.class); return hsQuery.queryResultSize(); }
private int countLocalIndex(Cache<String, Person> cache) { SearchManager sm = Search.getSearchManager(cache); ExtendedSearchIntegrator esi = sm.unwrap(ExtendedSearchIntegrator.class); IndexReader indexReader = esi.getIndexManager("person").getReaderProvider().openIndexReader(); return indexReader.numDocs(); }
private void useQuery(Cache<Object, Object> indexedCache) throws ParseException { indexedCache.put("1", new Person("A Person's Name", "A paragraph containing some text", 75)); CacheQuery<Person> cq = TestQueryHelperFactory.createCacheQuery(indexedCache, "name", "Name"); assertEquals(1, cq.getResultSize()); List<Person> l = cq.list(); assertEquals(1, l.size()); Person p = l.get(0); assertEquals("A Person's Name", p.getName()); assertEquals("A paragraph containing some text", p.getBlurb()); assertEquals(75, p.getAge()); SearchManager queryFactory = Search.getSearchManager(indexedCache); SearchIntegrator searchImpl = queryFactory.unwrap(SearchIntegrator.class); Set<IndexManager> indexManagers = searchImpl.getIndexBindings().get(Person.class).getIndexManagerSelector().all(); assert indexManagers != null && indexManagers.size() == 1; DirectoryBasedIndexManager directory = (DirectoryBasedIndexManager)indexManagers.iterator().next(); DirectoryProvider directoryProvider = directory.getDirectoryProvider(); assert directoryProvider instanceof RAMDirectoryProvider : "configuration properties where ignored"; } }
private void checkIndexPresence(Cache cache) { SearchIntegrator searchIntegrator = Search.getSearchManager(cache).unwrap(SearchIntegrator.class); verifyClassIsIndexed(searchIntegrator, getModelFactory().getUserImplClass()); verifyClassIsIndexed(searchIntegrator, getModelFactory().getAccountImplClass()); verifyClassIsIndexed(searchIntegrator, getModelFactory().getTransactionImplClass()); verifyClassIsNotIndexed(searchIntegrator, getModelFactory().getAddressImplClass()); }
public void testIndexPresence() { SearchIntegrator searchIntegrator = Search.getSearchManager((Cache) getCacheForQuery()).unwrap(SearchIntegrator.class); verifyClassIsIndexed(searchIntegrator, getModelFactory().getUserImplClass()); verifyClassIsIndexed(searchIntegrator, getModelFactory().getAccountImplClass()); verifyClassIsIndexed(searchIntegrator, getModelFactory().getTransactionImplClass()); verifyClassIsNotIndexed(searchIntegrator, getModelFactory().getAddressImplClass()); }
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); }
SearchIntegrator searchFactory = sm.unwrap(SearchIntegrator.class); assertNotNull(searchFactory.getIndexManager(ProgrammaticSearchMappingProviderImpl.getIndexName(cache.getName())));