use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class ElasticsearchExtensionIT method sort_nativeField_fromJson_string.
@Test
public void sort_nativeField_fromJson_string() {
StubMappingScope scope = mainIndex.createScope();
SearchQuery<DocumentReference> query = scope.query().where(f -> f.matchAll()).sort(f -> f.extension(ElasticsearchExtension.get()).fromJson("{'nativeField_sort1': 'asc'}").then().extension(ElasticsearchExtension.get()).fromJson("{'nativeField_sort2': 'asc'}").then().extension(ElasticsearchExtension.get()).fromJson("{'nativeField_sort3': 'asc'}").then().extension(ElasticsearchExtension.get()).fromJson("{'nativeField_sort4': {'order': 'asc', 'missing': '_last'}}").then().extension(ElasticsearchExtension.get()).fromJson("{'nativeField_sort5': {'order': 'asc', 'missing': '_first'}}")).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("{'nativeField_sort1': 'desc'}").then().extension(ElasticsearchExtension.get()).fromJson("{'nativeField_sort2': 'desc'}").then().extension(ElasticsearchExtension.get()).fromJson("{'nativeField_sort3': 'desc'}").then().extension(ElasticsearchExtension.get()).fromJson("{'nativeField_sort4': {'order': 'desc', 'missing': '_last'}}").then().extension(ElasticsearchExtension.get()).fromJson("{'nativeField_sort5': {'order': 'asc', 'missing': '_first'}}")).toQuery();
assertThatQuery(query).hasDocRefHitsExactOrder(mainIndex.typeName(), FOURTH_ID, THIRD_ID, SECOND_ID, FIRST_ID, EMPTY_ID, FIFTH_ID);
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class ElasticsearchExtensionIT method projection_jsonHit.
@Test
public void projection_jsonHit() {
StubMappingScope scope = mainIndex.createScope();
SearchQuery<JsonObject> query = scope.query().select(f -> f.extension(ElasticsearchExtension.get()).jsonHit()).where(f -> f.id().matching(FIRST_ID)).toQuery();
List<JsonObject> result = query.fetchAll().hits();
assertThat(result).hasSize(1);
assertJsonEquals("{" + "'_id': '" + FIRST_ID + "'," + "'_index': '" + defaultPrimaryName(mainIndex.name()) + "'" + "}", result.get(0).toString(), JSONCompareMode.LENIENT);
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class ElasticsearchExtensionIT method projection_explanation.
@Test
public void projection_explanation() {
StubMappingScope scope = mainIndex.createScope();
SearchQuery<JsonObject> query = scope.query().select(f -> f.extension(ElasticsearchExtension.get()).explanation()).where(f -> f.id().matching(FIRST_ID)).toQuery();
List<JsonObject> result = query.fetchAll().hits();
assertThat(result).hasSize(1);
assertThat(result.get(0)).asString().contains("\"description\":").contains("\"details\":");
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class ElasticsearchExtensionIT method aggregation_nativeField_fromJson_jsonObject.
@Test
public void aggregation_nativeField_fromJson_jsonObject() {
StubMappingScope scope = mainIndex.createScope();
AggregationKey<JsonObject> documentCountPerValue = AggregationKey.of("documentCountPerValue");
SearchQuery<DocumentReference> query = scope.query().extension(ElasticsearchExtension.get()).where(f -> f.matchAll()).aggregation(documentCountPerValue, f -> f.fromJson(gson.fromJson("{" + "'value_count' : {" + "'field' : 'nativeField_aggregation'" + " }" + "}", JsonObject.class))).toQuery();
JsonObject aggregationResult = query.fetchAll().aggregation(documentCountPerValue);
assertJsonEquals("{" + "'value': 3" + "}", aggregationResult.toString());
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class ElasticsearchExtensionIT method query.
@Test
public void query() {
StubMappingScope scope = mainIndex.createScope();
SearchQuery<DocumentReference> genericQuery = scope.query().where(f -> f.matchAll()).toQuery();
// Put the query and result into variables to check they have the right type
ElasticsearchSearchQuery<DocumentReference> query = genericQuery.extension(ElasticsearchExtension.get());
ElasticsearchSearchResult<DocumentReference> result = query.fetchAll();
assertThatResult(result).fromQuery(query).hasDocRefHitsAnyOrder(mainIndex.typeName(), FIRST_ID, SECOND_ID, THIRD_ID, FOURTH_ID, FIFTH_ID, EMPTY_ID).hasTotalHitCount(6);
// Unsupported extension
assertThatThrownBy(() -> query.extension((SearchQuery<DocumentReference> original, SearchLoadingContext<?, ?> loadingContext) -> Optional.empty())).isInstanceOf(SearchException.class);
}
Aggregations