Search in sources :

Example 1 with SearchMappingBuilder

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

the class LazySearchMapping method createMapping.

private SearchMapping createMapping() {
    IndexingConfiguration indexingConfiguration = cache.getCacheConfiguration().indexing();
    Set<String> indexedEntityTypes = indexingConfiguration.indexedEntityTypes();
    DataConversion valueDataConversion = cache.getAdvancedCache().getValueDataConversion();
    SearchMapping searchMapping = null;
    if (commonBuilding != null) {
        SearchMappingBuilder builder = SerializationContextSearchMapping.createBuilder(commonBuilding, entityLoader, indexedEntityTypes, serCtx);
        searchMapping = builder != null ? builder.build() : null;
    }
    if (indexingConfiguration.enabled()) {
        if (valueDataConversion.getStorageMediaType().match(APPLICATION_PROTOSTREAM)) {
            // Try to resolve the indexed type names to protobuf type names.
            Set<String> knownTypes = protobufMetadataManager.getSerializationContext().getGenericDescriptors().keySet();
            for (String typeName : indexedEntityTypes) {
                if (!knownTypes.contains(typeName)) {
                    if (searchMapping != null)
                        searchMapping.close();
                    throw log.unknownType(typeName);
                }
                if (searchMapping == null || searchMapping.indexedEntity(typeName) == null) {
                    if (searchMapping != null)
                        searchMapping.close();
                    throw log.typeNotIndexed(typeName);
                }
            }
        }
    }
    return searchMapping;
}
Also used : DataConversion(org.infinispan.encoding.DataConversion) SearchMappingBuilder(org.infinispan.search.mapper.mapping.SearchMappingBuilder) SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) SerializationContextSearchMapping(org.infinispan.query.remote.impl.mapping.SerializationContextSearchMapping) IndexingConfiguration(org.infinispan.configuration.cache.IndexingConfiguration)

Example 2 with SearchMappingBuilder

use of org.infinispan.search.mapper.mapping.SearchMappingBuilder 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)

Example 3 with SearchMappingBuilder

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

the class SerializationContextSearchMapping method createBuilder.

public static SearchMappingBuilder createBuilder(SearchMappingCommonBuilding commonBuilding, EntityLoader<EntityReference, ?> entityLoader, Set<String> indexedEntityTypes, SerializationContext serializationContext) {
    GlobalReferenceHolder globalReferenceHolder = new GlobalReferenceHolder(serializationContext.getGenericDescriptors());
    ProtobufBootstrapIntrospector introspector = new ProtobufBootstrapIntrospector();
    SearchMappingBuilder builder = commonBuilding.builder(introspector);
    builder.setEntityLoader(entityLoader);
    builder.setEntityConverter(new ProtobufEntityConverter(serializationContext, globalReferenceHolder.getRootMessages()));
    ProgrammaticMappingConfigurationContext programmaticMapping = builder.programmaticMapping();
    boolean existIndexedEntities = false;
    for (GlobalReferenceHolder.RootMessageInfo rootMessage : globalReferenceHolder.getRootMessages()) {
        String fullName = rootMessage.getFullName();
        if (!indexedEntityTypes.contains(fullName)) {
            continue;
        }
        existIndexedEntities = true;
        programmaticMapping.type(fullName).binder(new ProtobufMessageBinder(globalReferenceHolder, fullName)).indexed().index(rootMessage.getIndexName());
        builder.addEntityType(byte[].class, fullName);
    }
    return existIndexedEntities ? builder : null;
}
Also used : ProtobufBootstrapIntrospector(org.infinispan.query.remote.impl.mapping.model.ProtobufBootstrapIntrospector) SearchMappingBuilder(org.infinispan.search.mapper.mapping.SearchMappingBuilder) GlobalReferenceHolder(org.infinispan.query.remote.impl.mapping.reference.GlobalReferenceHolder) ProtobufEntityConverter(org.infinispan.query.remote.impl.indexing.ProtobufEntityConverter) ProgrammaticMappingConfigurationContext(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext) ProtobufMessageBinder(org.infinispan.query.remote.impl.mapping.typebridge.ProtobufMessageBinder)

Aggregations

SearchMappingBuilder (org.infinispan.search.mapper.mapping.SearchMappingBuilder)3 SearchMapping (org.infinispan.search.mapper.mapping.SearchMapping)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 ProgrammaticMappingConfigurationContext (org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext)1 IndexingConfiguration (org.infinispan.configuration.cache.IndexingConfiguration)1 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)1 DataConversion (org.infinispan.encoding.DataConversion)1 ProtobufEntityConverter (org.infinispan.query.remote.impl.indexing.ProtobufEntityConverter)1 SerializationContextSearchMapping (org.infinispan.query.remote.impl.mapping.SerializationContextSearchMapping)1 ProtobufBootstrapIntrospector (org.infinispan.query.remote.impl.mapping.model.ProtobufBootstrapIntrospector)1 GlobalReferenceHolder (org.infinispan.query.remote.impl.mapping.reference.GlobalReferenceHolder)1 ProtobufMessageBinder (org.infinispan.query.remote.impl.mapping.typebridge.ProtobufMessageBinder)1 ProgrammaticSearchMappingProvider (org.infinispan.search.mapper.mapping.ProgrammaticSearchMappingProvider)1 SearchMappingCommonBuilding (org.infinispan.search.mapper.mapping.SearchMappingCommonBuilding)1