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);
}
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);
}
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);
}
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();
}
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);
}
Aggregations