use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class CompositeSearchProjectionIT method compositeList_fromSearchProjectionObjects.
@Test
public void compositeList_fromSearchProjectionObjects() {
StubMappingScope scope = index.createScope();
SearchQuery<List<?>> query = scope.query().select(f -> f.composite(f.field(index.binding().author.relativeFieldName, String.class).toProjection(), f.field(index.binding().title.relativeFieldName, String.class).toProjection())).where(f -> f.matchAll()).toQuery();
assertThatQuery(query).hasHitsAnyOrder(Arrays.asList(index.binding().author.document1Value.indexedValue, index.binding().title.document1Value.indexedValue), Arrays.asList(index.binding().author.document2Value.indexedValue, index.binding().title.document2Value.indexedValue), Arrays.asList(index.binding().author.document3Value.indexedValue, index.binding().title.document3Value.indexedValue));
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class CompositeSearchProjectionIT method nestedComposite.
@Test
public void nestedComposite() {
StubMappingScope scope = index.createScope();
SearchQuery<Book_Bi_Score> query = scope.query().select(f -> f.composite(Book_Bi_Score::new, f.composite(Book_Bi::new, f.field(index.binding().author.relativeFieldName, String.class), f.field(index.binding().title.relativeFieldName, String.class)), f.score())).where(f -> f.matchAll()).toQuery();
assertThatQuery(query).hasHitsAnyOrder(new Book_Bi_Score(new Book_Bi(index.binding().author.document1Value.indexedValue, index.binding().title.document1Value.indexedValue), 1.0F), new Book_Bi_Score(new Book_Bi(index.binding().author.document2Value.indexedValue, index.binding().title.document2Value.indexedValue), 1.0F), new Book_Bi_Score(new Book_Bi(index.binding().author.document3Value.indexedValue, index.binding().title.document3Value.indexedValue), 1.0F));
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class ElasticsearchExtensionIT method projection_nativeField_withProjectionConverters_disabled.
@Test
public void projection_nativeField_withProjectionConverters_disabled() {
StubMappingScope scope = mainIndex.createScope();
SearchQuery<JsonElement> query = scope.query().select(f -> f.field("nativeField_integer_converted", JsonElement.class, ValueConvert.NO)).where(f -> f.id().matching(SECOND_ID)).toQuery();
assertThatQuery(query).hasHitsAnyOrder(new JsonPrimitive(2));
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class ElasticsearchExtensionIT method predicate_nativeField_withDslConverter_disabled.
@Test
public void predicate_nativeField_withDslConverter_disabled() {
StubMappingScope scope = mainIndex.createScope();
SearchQuery<DocumentReference> query = scope.query().where(f -> f.match().field("nativeField_integer_converted").matching(new JsonPrimitive(2), ValueConvert.NO)).toQuery();
assertThatQuery(query).hasDocRefHitsAnyOrder(mainIndex.typeName(), SECOND_ID).hasTotalHitCount(1);
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class ElasticsearchExtensionIT method sort_nativeField_jsonObject.
@Test
public void sort_nativeField_jsonObject() {
StubMappingScope scope = mainIndex.createScope();
SearchQuery<DocumentReference> query = scope.query().where(f -> f.matchAll()).sort(f -> f.extension(ElasticsearchExtension.get()).fromJson(gson.fromJson("{'nativeField_sort1': 'asc'}", JsonObject.class)).then().extension(ElasticsearchExtension.get()).fromJson(gson.fromJson("{'nativeField_sort2': 'asc'}", JsonObject.class)).then().extension(ElasticsearchExtension.get()).fromJson(gson.fromJson("{'nativeField_sort3': 'asc'}", JsonObject.class)).then().extension(ElasticsearchExtension.get()).fromJson(gson.fromJson("{'nativeField_sort4': {'order': 'asc', 'missing': '_last'}}", JsonObject.class)).then().extension(ElasticsearchExtension.get()).fromJson(gson.fromJson("{'nativeField_sort5': {'order': 'asc', 'missing': '_first'}}", JsonObject.class))).toQuery();
assertThatQuery(query).hasDocRefHitsExactOrder(mainIndex.typeName(), FIRST_ID, SECOND_ID, THIRD_ID, FOURTH_ID, EMPTY_ID, FIFTH_ID);
query = scope.query().where(f -> f.matchAll()).sort(f -> f.extension(ElasticsearchExtension.get()).fromJson(gson.fromJson("{'nativeField_sort1': 'desc'}", JsonObject.class)).then().extension(ElasticsearchExtension.get()).fromJson(gson.fromJson("{'nativeField_sort2': 'desc'}", JsonObject.class)).then().extension(ElasticsearchExtension.get()).fromJson(gson.fromJson("{'nativeField_sort3': 'desc'}", JsonObject.class)).then().extension(ElasticsearchExtension.get()).fromJson(gson.fromJson("{'nativeField_sort4': {'order': 'desc', 'missing': '_last'}}", JsonObject.class)).then().extension(ElasticsearchExtension.get()).fromJson(gson.fromJson("{'nativeField_sort5': {'order': 'asc', 'missing': '_first'}}", JsonObject.class))).toQuery();
assertThatQuery(query).hasDocRefHitsExactOrder(mainIndex.typeName(), FOURTH_ID, THIRD_ID, SECOND_ID, FIRST_ID, EMPTY_ID, FIFTH_ID);
}
Aggregations