use of org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope in project hibernate-search by hibernate.
the class FieldSearchSortTypeCheckingAndConversionIT method multiIndex_withCompatibleIndex_usingField.
@Test
public void multiIndex_withCompatibleIndex_usingField() {
StubMappingScope scope = mainIndex.createScope(compatibleIndex);
SearchQuery<DocumentReference> query;
String fieldPath = getFieldPath();
query = matchAllQuery(f -> f.field(fieldPath).asc().missing().use(getSingleValueForMissingUse(BEFORE_DOCUMENT_1_ORDINAL)), 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(compatibleIndex.typeName(), COMPATIBLE_INDEX_DOCUMENT_1);
});
}
use of org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope in project hibernate-search by hibernate.
the class FieldSearchSortUnsupportedTypesIT method error_notSupported.
@Test
@TestForIssue(jiraKey = "HSEARCH-3798")
public void error_notSupported() {
StubMappingScope scope = index.createScope();
String absoluteFieldPath = getFieldPath();
assertThatThrownBy(() -> scope.sort().field(absoluteFieldPath)).isInstanceOf(SearchException.class).hasMessageContainingAll("Cannot use 'sort:field' on field '" + absoluteFieldPath + "'", "'sort:field' is not available for fields of this type").satisfies(FailureReportUtils.hasContext(EventContexts.fromIndexFieldAbsolutePath(absoluteFieldPath)));
}
use of org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope in project hibernate-search by hibernate.
the class DistanceSearchProjectionComplexCasesIT method withDistanceSort.
/**
* See also {@link DistanceSearchProjectionSingleValuedBaseIT#sortable_withSort()}.
* <p>
* The main difference is that we're composing multiple sorts here.
*/
@Test
public void withDistanceSort() {
StubMappingScope scope = mainIndex.createScope();
GeoPoint center = GeoPoint.of(45.749828, 4.854172);
assertThatQuery(scope.query().select(f -> f.distance("geoPoint", center)).where(f -> f.matchAll()).sort(f -> f.distance("geoPoint", GeoPoint.of(43.749828, 1.854172)).then().distance("geoPoint", center)).toQuery()).hits().asIs().usingElementComparator(APPROX_M_COMPARATOR).containsExactly(1300d, 430d, 2730d, null);
}
use of org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope in project hibernate-search by hibernate.
the class DistanceSearchProjectionComplexCasesIT method several.
/**
* See also {@link DistanceSearchProjectionSingleValuedBaseIT#several()}.
* <p>
* The main difference is that we're targeting multiple fields here.
*/
@Test
public void several() {
StubMappingScope scope = mainIndex.createScope();
ListAssert<List<?>> hitsAssert = assertThatQuery(scope.query().select(f -> f.composite(f.distance("geoPoint", GeoPoint.of(45.749828, 4.854172)), f.distance("geoPoint", GeoPoint.of(45.763363, 4.833527)), f.distance("geoPoint_1", GeoPoint.of(45.749828, 4.854172)).unit(DistanceUnit.KILOMETERS))).where(f -> f.matchAll()).sort(f -> f.field("string").missing().last().asc()).toQuery()).hits().asIs();
hitsAssert.extracting(tuple -> (Double) tuple.get(0)).usingElementComparator(APPROX_M_COMPARATOR).containsExactlyInAnyOrder(430d, 1300d, 2730d, null);
hitsAssert.extracting(tuple -> (Double) tuple.get(1)).usingElementComparator(APPROX_M_COMPARATOR).containsExactlyInAnyOrder(1780d, 1095d, 812d, null);
hitsAssert.extracting(tuple -> (Double) tuple.get(2)).usingElementComparator(APPROX_KM_COMPARATOR).containsExactlyInAnyOrder(135.834, 136.294, 134.967, null);
}
use of org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope in project hibernate-search by hibernate.
the class DistanceSearchProjectionComplexCasesIT method longFieldName.
/**
* Test that projections will work even with very long field names.
* <p>
* This is relevant for Elasticsearch, which generates a name for computed values based on the field name.
*/
@Test
public void longFieldName() {
StubMappingScope scope = mainIndex.createScope();
assertThatQuery(scope.query().select(f -> f.distance("geoPoint_with_a_veeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy_long_name", GeoPoint.of(45.74982800099999888371, 4.85417200099999888371))).where(f -> f.matchAll()).toQuery()).hits().asIs().usingElementComparator(APPROX_M_COMPARATOR).containsExactlyInAnyOrder(430d, 1300d, 2730d, null);
}
Aggregations