Search in sources :

Example 11 with SearchMapping

use of org.infinispan.search.mapper.mapping.SearchMapping in project infinispan by infinispan.

the class ProtobufValueWrapperIndexingTest method testIndexingWithWrapper.

public void testIndexingWithWrapper() {
    SearchMapping searchMapping = ComponentRegistryUtils.getSearchMapping(cache);
    assertNotNull(searchMapping);
    // Store some test data:
    cache.put(new byte[] { 1, 2, 3 }, createUser("Adrian", "Nistor"));
    cache.put(new byte[] { 4, 5, 6 }, createUser("John", "Batman"));
    SearchSession session = searchMapping.getMappingSession();
    SearchScope<byte[]> scope = session.scope(byte[].class, "sample_bank_account.User");
    SearchQuery<Object> query = session.search(scope).select(f -> f.field("surname")).where(f -> f.match().field("name").matching("Adrian")).toQuery();
    List<Object> result = query.fetchAllHits();
    assertEquals(1, result.size());
    assertEquals("Nistor", result.get(0));
}
Also used : SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) SingleCacheManagerTest(org.infinispan.test.SingleCacheManagerTest) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) SearchScope(org.infinispan.search.mapper.scope.SearchScope) Address(org.infinispan.protostream.sampledomain.Address) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) SearchSession(org.infinispan.search.mapper.session.SearchSession) Assert.assertEquals(org.testng.Assert.assertEquals) TransactionMode(org.infinispan.transaction.TransactionMode) Test(org.testng.annotations.Test) User(org.infinispan.protostream.sampledomain.User) List(java.util.List) MediaType(org.infinispan.commons.dataconversion.MediaType) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) TestCacheManagerFactory(org.infinispan.test.fwk.TestCacheManagerFactory) AssertJUnit.assertNotNull(org.testng.AssertJUnit.assertNotNull) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) LOCAL_HEAP(org.infinispan.configuration.cache.IndexStorage.LOCAL_HEAP) ComponentRegistryUtils(org.infinispan.query.impl.ComponentRegistryUtils) Collections(java.util.Collections) SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) SearchSession(org.infinispan.search.mapper.session.SearchSession)

Example 12 with SearchMapping

use of org.infinispan.search.mapper.mapping.SearchMapping in project infinispan by infinispan.

the class JBMARRemoteQueryDslConditionsTest method testIndexPresence.

@Override
public void testIndexPresence() {
    SearchMapping searchMapping = TestingUtil.extractComponent(cache, SearchMapping.class);
    verifyClassIsIndexed(searchMapping, getModelFactory().getUserImplClass());
    verifyClassIsIndexed(searchMapping, getModelFactory().getAccountImplClass());
    verifyClassIsIndexed(searchMapping, getModelFactory().getTransactionImplClass());
    verifyClassIsNotIndexed(searchMapping, getModelFactory().getAddressImplClass());
}
Also used : SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping)

Example 13 with SearchMapping

use of org.infinispan.search.mapper.mapping.SearchMapping in project infinispan by infinispan.

the class RemoteQueryDslConditionsTest method testIndexPresence.

@Override
public void testIndexPresence() {
    SearchMapping searchMapping = TestingUtil.extractComponent(cache, SearchMapping.class);
    // we have indexing for remote query!
    assertNotNull(searchMapping.indexedEntity("sample_bank_account.User"));
    assertNotNull(searchMapping.indexedEntity("sample_bank_account.Account"));
    assertNotNull(searchMapping.indexedEntity("sample_bank_account.Transaction"));
    // we have some indexes for this cache
    assertEquals(3, searchMapping.allIndexedEntities().size());
}
Also used : SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping)

Example 14 with SearchMapping

use of org.infinispan.search.mapper.mapping.SearchMapping in project infinispan by infinispan.

the class QueryDslConditionsTest method testIndexPresence.

public void testIndexPresence() {
    SearchMapping searchMapping = TestingUtil.extractComponent((Cache<?, ?>) getCacheForQuery(), SearchMapping.class);
    verifyClassIsIndexed(searchMapping, getModelFactory().getUserImplClass());
    verifyClassIsIndexed(searchMapping, getModelFactory().getAccountImplClass());
    verifyClassIsIndexed(searchMapping, getModelFactory().getTransactionImplClass());
    verifyClassIsNotIndexed(searchMapping, getModelFactory().getAddressImplClass());
}
Also used : SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping)

Example 15 with SearchMapping

use of org.infinispan.search.mapper.mapping.SearchMapping in project infinispan by infinispan.

the class LifecycleManager method createSearchMapping.

private SearchMapping createSearchMapping(LocalQueryStatistics queryStatistics, IndexingConfiguration indexingConfiguration, Map<String, Class<?>> indexedClasses, ComponentRegistry cr, AdvancedCache<?, ?> cache, KeyTransformationHandler keyTransformationHandler, ClassLoader aggregatedClassLoader) {
    SearchMapping searchMapping = cr.getComponent(SearchMapping.class);
    if (searchMapping != null && !searchMapping.isClose()) {
        // a paranoid check against an unlikely failure
        throw new IllegalStateException("SearchIntegrator already initialized!");
    }
    GlobalConfiguration globalConfiguration = cr.getGlobalComponentRegistry().getGlobalConfiguration();
    // load ProgrammaticSearchMappingProviders from classpath
    Collection<ProgrammaticSearchMappingProvider> mappingProviders = ServiceFinder.load(ProgrammaticSearchMappingProvider.class, aggregatedClassLoader);
    SearchMappingCommonBuilding commonBuilding = new SearchMappingCommonBuilding(KeyTransformationHandlerIdentifierBridge.createReference(keyTransformationHandler), extractProperties(globalConfiguration, indexingConfiguration, aggregatedClassLoader), aggregatedClassLoader, mappingProviders);
    Set<Class<?>> types = new HashSet<>(indexedClasses.values());
    if (!types.isEmpty()) {
        // use the common builder to create the mapping now
        SearchMappingBuilder builder = commonBuilding.builder(SearchMappingBuilder.introspector(MethodHandles.lookup()));
        builder.setEntityLoader(new EntityLoader<>(queryStatistics, cache, keyTransformationHandler));
        builder.addEntityTypes(types);
        searchMapping = builder.build();
        cr.registerComponent(searchMapping, SearchMapping.class);
    }
    if (searchMapping == null) {
        // register the common builder to create the mapping at a later time
        cr.registerComponent(commonBuilding, SearchMappingCommonBuilding.class);
    }
    return searchMapping;
}
Also used : GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) SearchMappingBuilder(org.infinispan.search.mapper.mapping.SearchMappingBuilder) SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) ProgrammaticSearchMappingProvider(org.infinispan.search.mapper.mapping.ProgrammaticSearchMappingProvider) SearchMappingCommonBuilding(org.infinispan.search.mapper.mapping.SearchMappingCommonBuilding) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

SearchMapping (org.infinispan.search.mapper.mapping.SearchMapping)20 AdvancedCache (org.infinispan.AdvancedCache)4 Cache (org.infinispan.Cache)3 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)3 QueryInterceptor (org.infinispan.query.backend.QueryInterceptor)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 MediaType (org.infinispan.commons.dataconversion.MediaType)2 IndexingConfiguration (org.infinispan.configuration.cache.IndexingConfiguration)2 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)2 DataConversion (org.infinispan.encoding.DataConversion)2 ComponentRegistry (org.infinispan.factories.ComponentRegistry)2 ReflectionEntityNamesResolver (org.infinispan.objectfilter.impl.syntax.parser.ReflectionEntityNamesResolver)2 SerializationContext (org.infinispan.protostream.SerializationContext)2 Indexer (org.infinispan.query.Indexer)2 KeyTransformationHandler (org.infinispan.query.backend.KeyTransformationHandler)2 QueryCache (org.infinispan.query.core.impl.QueryCache)2 IndexStatistics (org.infinispan.query.core.stats.IndexStatistics)2