Search in sources :

Example 1 with SearchPredicate

use of org.hibernate.search.engine.search.predicate.SearchPredicate 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 SearchPredicate

use of org.hibernate.search.engine.search.predicate.SearchPredicate in project hibernate-search by hibernate.

the class ElasticsearchExtensionIT method predicate_nativeField_fromJson_jsonObject_separatePredicate.

@Test
public void predicate_nativeField_fromJson_jsonObject_separatePredicate() {
    StubMappingScope scope = mainIndex.createScope();
    SearchPredicate predicate1 = scope.predicate().extension(ElasticsearchExtension.get()).fromJson(gson.fromJson("{'match': {'nativeField_string': 'text 1'}}", JsonObject.class)).toPredicate();
    SearchPredicate predicate2 = scope.predicate().extension(ElasticsearchExtension.get()).fromJson(gson.fromJson("{'match': {'nativeField_integer': 2}}", JsonObject.class)).toPredicate();
    SearchPredicate predicate3 = scope.predicate().extension(ElasticsearchExtension.get()).fromJson(gson.fromJson("{" + "'geo_distance': {" + "'distance': '200km'," + "'nativeField_geoPoint': {" + "'lat': 40," + "'lon': -70" + "}" + "}" + "}", JsonObject.class)).toPredicate();
    SearchPredicate booleanPredicate = scope.predicate().bool().should(predicate1).should(predicate2).should(predicate3).toPredicate();
    SearchQuery<DocumentReference> query = scope.query().where(booleanPredicate).toQuery();
    assertThatQuery(query).hasDocRefHitsAnyOrder(mainIndex.typeName(), FIRST_ID, SECOND_ID, THIRD_ID).hasTotalHitCount(3);
}
Also used : StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Test(org.junit.Test)

Example 3 with SearchPredicate

use of org.hibernate.search.engine.search.predicate.SearchPredicate in project hibernate-search by hibernate.

the class ElasticsearchExtensionIT method predicate_nativeField_fromJson_string_separatePredicate.

@Test
public void predicate_nativeField_fromJson_string_separatePredicate() {
    StubMappingScope scope = mainIndex.createScope();
    SearchPredicate predicate1 = scope.predicate().extension(ElasticsearchExtension.get()).fromJson("{'match': {'nativeField_string': 'text 1'}}").toPredicate();
    SearchPredicate predicate2 = scope.predicate().extension(ElasticsearchExtension.get()).fromJson("{'match': {'nativeField_integer': 2}}").toPredicate();
    SearchPredicate predicate3 = scope.predicate().extension(ElasticsearchExtension.get()).fromJson("{" + "'geo_distance': {" + "'distance': '200km'," + "'nativeField_geoPoint': {" + "'lat': 40," + "'lon': -70" + "}" + "}" + "}").toPredicate();
    SearchPredicate booleanPredicate = scope.predicate().bool().should(predicate1).should(predicate2).should(predicate3).toPredicate();
    SearchQuery<DocumentReference> query = scope.query().where(booleanPredicate).toQuery();
    assertThatQuery(query).hasDocRefHitsAnyOrder(mainIndex.typeName(), FIRST_ID, SECOND_ID, THIRD_ID).hasTotalHitCount(3);
}
Also used : StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Test(org.junit.Test)

Example 4 with SearchPredicate

use of org.hibernate.search.engine.search.predicate.SearchPredicate in project hibernate-search by hibernate.

the class AbstractSearchQueryOptionsStep method where.

@Override
public S where(Function<? super PDF, ? extends PredicateFinalStep> predicateContributor) {
    SearchPredicate predicate = predicateContributor.apply(predicateFactory()).toPredicate();
    searchQueryBuilder.predicate(predicate);
    return thisAsS();
}
Also used : SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate)

Example 5 with SearchPredicate

use of org.hibernate.search.engine.search.predicate.SearchPredicate in project hibernate-search by hibernate.

the class SearchPredicateIT method where_searchPredicate.

@Test
public void where_searchPredicate() {
    StubMappingScope scope = mainIndex.createScope();
    SearchPredicate predicate = scope.predicate().match().field("string").matching(STRING_1).toPredicate();
    SearchQuery<DocumentReference> query = scope.query().where(predicate).toQuery();
    assertThatQuery(query).hasDocRefHitsAnyOrder(mainIndex.typeName(), DOCUMENT_1);
}
Also used : StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Test(org.junit.Test)

Aggregations

SearchPredicate (org.hibernate.search.engine.search.predicate.SearchPredicate)28 Test (org.junit.Test)21 StubMappingScope (org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope)18 SearchPredicateFactory (org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory)12 DocumentReference (org.hibernate.search.engine.backend.common.DocumentReference)8 IndexFieldReference (org.hibernate.search.engine.backend.document.IndexFieldReference)7 IndexSchemaElement (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement)7 SearchSetupHelper (org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper)7 SearchException (org.hibernate.search.util.common.SearchException)7 SearchResultAssert.assertThatQuery (org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery)7 SimpleMappedIndex (org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex)7 IndexObjectFieldReference (org.hibernate.search.engine.backend.document.IndexObjectFieldReference)6 IndexSchemaObjectField (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField)6 ObjectStructure (org.hibernate.search.engine.backend.types.ObjectStructure)6 TestForIssue (org.hibernate.search.util.impl.test.annotation.TestForIssue)6 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)5 DocumentElement (org.hibernate.search.engine.backend.document.DocumentElement)5 BeforeClass (org.junit.BeforeClass)5 ClassRule (org.junit.ClassRule)5 BulkIndexer (org.hibernate.search.util.impl.integrationtest.mapper.stub.BulkIndexer)4