use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class FieldSearchSortTypeCheckingAndConversionIT method multiIndex_withRawFieldCompatibleIndex_dslConverterDisabled.
@Test
public void multiIndex_withRawFieldCompatibleIndex_dslConverterDisabled() {
StubMappingScope scope = mainIndex.createScope(rawFieldCompatibleIndex);
SearchQuery<DocumentReference> query;
String fieldPath = getFieldPath();
query = matchAllQuery(f -> f.field(fieldPath).asc().missing().use(getSingleValueForMissingUse(BEFORE_DOCUMENT_1_ORDINAL), ValueConvert.NO), scope);
/*
* Not testing the ordering of results here because some documents have the same value.
* It's not what we want to test anyway: we just want to check that fields are correctly
* detected as compatible and that no exception is thrown.
*/
assertThatQuery(query).hasDocRefHitsAnyOrder(b -> {
b.doc(mainIndex.typeName(), EMPTY);
b.doc(mainIndex.typeName(), DOCUMENT_1);
b.doc(mainIndex.typeName(), DOCUMENT_2);
b.doc(mainIndex.typeName(), DOCUMENT_3);
b.doc(rawFieldCompatibleIndex.typeName(), RAW_FIELD_COMPATIBLE_INDEX_DOCUMENT_1);
});
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class DistanceSearchSearchableSortableIT method searchableSortable.
@Test
public void searchableSortable() {
StubMappingScope scope = index.createScope();
SearchQuery<DocumentReference> query = scope.query().where(f -> f.spatial().within().field("searchableSortable").circle(METRO_GARIBALDI, 1_500)).sort(f -> f.distance("searchableSortable", METRO_GARIBALDI)).toQuery();
assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), CHEZ_MARGOTTE_ID, IMOUTO_ID);
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class DistanceSearchSearchableSortableIT method searchableNotSortable.
@Test
public void searchableNotSortable() {
StubMappingScope scope = index.createScope();
String fieldPath = "searchableNotSortable";
assertThatThrownBy(() -> scope.query().where(f -> f.spatial().within().field(fieldPath).circle(METRO_GARIBALDI, 1_500)).sort(f -> f.distance(fieldPath, METRO_GARIBALDI)).toQuery()).isInstanceOf(SearchException.class).hasMessageContainingAll("Cannot use 'sort:distance' on field '" + fieldPath + "'", "Make sure the field is marked as searchable/sortable/projectable/aggregable (whichever is relevant)");
SearchQuery<DocumentReference> query = scope.query().where(f -> f.spatial().within().field(fieldPath).circle(METRO_GARIBALDI, 1_500)).toQuery();
assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), CHEZ_MARGOTTE_ID, IMOUTO_ID);
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class DistanceSearchSearchableSortableIT method defaultSearchableSortable.
@Test
public void defaultSearchableSortable() {
StubMappingScope scope = index.createScope();
SearchQuery<DocumentReference> query = scope.query().where(f -> f.spatial().within().field("defaultSearchableSortable").circle(METRO_GARIBALDI, 1_500)).sort(f -> f.distance("defaultSearchableSortable", METRO_GARIBALDI)).toQuery();
assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), CHEZ_MARGOTTE_ID, IMOUTO_ID);
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class DistanceSearchSearchableSortableIT method notSearchableSortable.
@Test
public void notSearchableSortable() {
StubMappingScope scope = index.createScope();
String fieldPath = "notSearchableSortable";
assertThatThrownBy(() -> scope.query().where(f -> f.spatial().within().field(fieldPath).circle(METRO_GARIBALDI, 1_500)).sort(f -> f.distance(fieldPath, METRO_GARIBALDI)).toQuery()).isInstanceOf(SearchException.class).hasMessageContainingAll("Cannot use 'predicate:spatial:within-circle' on field '" + fieldPath + "'");
SearchQuery<DocumentReference> query = scope.query().where(f -> f.matchAll()).sort(f -> f.distance(fieldPath, METRO_GARIBALDI)).toQuery();
assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), CHEZ_MARGOTTE_ID, IMOUTO_ID, OURSON_QUI_BOIT_ID);
}
Aggregations