Search in sources :

Example 1 with SearchSession

use of org.infinispan.search.mapper.session.SearchSession in project infinispan by infinispan.

the class SearchQueryMaker method transform.

public SearchQueryParsingResult transform(IckleParsingResult<TypeMetadata> parsingResult, Map<String, Object> namedParameters, Class<?> targetedType, String targetedTypeName) {
    if (searchMapping == null) {
        throw log.noTypeIsIndexed(parsingResult.getQueryString());
    }
    this.namedParameters = namedParameters;
    SearchSession querySession = searchMapping.getMappingSession();
    SearchScope<?> scope = targetedTypeName == null ? querySession.scope(targetedType) : querySession.scope(targetedType, targetedTypeName);
    predicateFactory = scope.predicate().extension(LuceneExtension.get());
    indexedEntity = targetedTypeName == null ? searchMapping.indexedEntity(targetedType) : searchMapping.indexedEntity(targetedTypeName);
    SearchPredicate predicate = makePredicate(parsingResult.getWhereClause()).toPredicate();
    SearchProjectionInfo projection = makeProjection(parsingResult.getTargetEntityMetadata(), scope.projection(), parsingResult.getProjections(), parsingResult.getProjectedTypes());
    SearchSort sort = makeSort(scope.sort(), parsingResult.getSortFields());
    return new SearchQueryParsingResult(targetedType, targetedTypeName, projection, predicate, sort);
}
Also used : SearchSession(org.infinispan.search.mapper.session.SearchSession) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) SearchSort(org.hibernate.search.engine.search.sort.SearchSort)

Example 2 with SearchSession

use of org.infinispan.search.mapper.session.SearchSession 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 3 with SearchSession

use of org.infinispan.search.mapper.session.SearchSession in project infinispan by infinispan.

the class LocalIndexStatistics method indexInfos.

private CompletionStage<IndexInfo> indexInfos(SearchIndexedEntity indexedEntity) {
    SearchSession session = searchMapping.getMappingSession();
    SearchScope<?> scope = session.scope(indexedEntity.javaClass(), indexedEntity.name());
    CompletionStage<Long> countStage = blockingManager.supplyBlocking(() -> session.search(scope).where(SearchPredicateFactory::matchAll).fetchTotalHitCount(), this);
    CompletionStage<Long> sizeStage = indexedEntity.indexManager().unwrap(LuceneIndexManager.class).computeSizeInBytesAsync();
    return countStage.thenCombine(sizeStage, IndexInfo::new);
}
Also used : SearchPredicateFactory(org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory) LuceneIndexManager(org.hibernate.search.backend.lucene.index.LuceneIndexManager) SearchSession(org.infinispan.search.mapper.session.SearchSession) IndexInfo(org.infinispan.query.core.stats.IndexInfo)

Aggregations

SearchSession (org.infinispan.search.mapper.session.SearchSession)3 Collections (java.util.Collections)1 List (java.util.List)1 LuceneIndexManager (org.hibernate.search.backend.lucene.index.LuceneIndexManager)1 SearchPredicate (org.hibernate.search.engine.search.predicate.SearchPredicate)1 SearchPredicateFactory (org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory)1 SearchQuery (org.hibernate.search.engine.search.query.SearchQuery)1 SearchSort (org.hibernate.search.engine.search.sort.SearchSort)1 MediaType (org.infinispan.commons.dataconversion.MediaType)1 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)1 LOCAL_HEAP (org.infinispan.configuration.cache.IndexStorage.LOCAL_HEAP)1 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1 Address (org.infinispan.protostream.sampledomain.Address)1 User (org.infinispan.protostream.sampledomain.User)1 IndexInfo (org.infinispan.query.core.stats.IndexInfo)1 ComponentRegistryUtils (org.infinispan.query.impl.ComponentRegistryUtils)1 SearchMapping (org.infinispan.search.mapper.mapping.SearchMapping)1 SearchScope (org.infinispan.search.mapper.scope.SearchScope)1 SingleCacheManagerTest (org.infinispan.test.SingleCacheManagerTest)1