Skip to content

Commit

Permalink
HSEARCH-3863 Test validation on missing options on ES sort
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever committed Feb 8, 2021
1 parent 10be35e commit 4891b6b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
Expand Up @@ -132,4 +132,14 @@ public boolean supportsExistsForFieldWithoutDocValues(Class<?> fieldType) {
}
return true;
}

@Override
public boolean geoDistanceSortingSupportsConfigurableMissingValues() {
// See https://www.elastic.co/guide/en/elasticsearch/reference/7.10/sort-search-results.html
// In particular:
// geo distance sorting does not support configurable missing values:
// the distance will always be considered equal to Infinity when a document does not have values for the field
// that is used for distance computation.
return false;
}
}
Expand Up @@ -31,6 +31,7 @@
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.FieldTypeDescriptor;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.GeoPointFieldTypeDescriptor;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.AscendingUniqueDistanceFromCenterValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.util.TckConfiguration;
import org.hibernate.search.integrationtest.backend.tck.testsupport.util.TestedFieldStructure;
import org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper;
import org.hibernate.search.util.common.SearchException;
Expand Down Expand Up @@ -186,6 +187,16 @@ public void missingValue_explicit() {
assertThatQuery( query )
.hasDocRefHitsExactOrder( index.typeName(), dataSet.doc1Id, dataSet.doc2Id, dataSet.doc3Id, dataSet.emptyDoc1Id );

if ( !TckConfiguration.get().getBackendFeatures().geoDistanceSortingSupportsConfigurableMissingValues() ) {
assertThatThrownBy( () -> simpleQuery(
dataSetForDesc,
b -> b.distance( fieldPath, CENTER_POINT.latitude(), CENTER_POINT.longitude() )
.desc().missing().last()
) )
.isInstanceOf( SearchException.class )
.hasMessageContainingAll( "Missing last on sort with descending order is not supported." );
}

// Explicit order with missing().first()
dataSet = dataSetForDesc;
query = simpleQuery(
Expand All @@ -195,6 +206,27 @@ public void missingValue_explicit() {
);
assertThatQuery( query )
.hasDocRefHitsExactOrder( index.typeName(), dataSet.emptyDoc1Id, dataSet.doc3Id, dataSet.doc2Id, dataSet.doc1Id );

if ( !TckConfiguration.get().getBackendFeatures().geoDistanceSortingSupportsConfigurableMissingValues() ) {
assertThatThrownBy( () -> simpleQuery(
dataSetForAsc,
b -> b.distance( fieldPath, CENTER_POINT.latitude(), CENTER_POINT.longitude() )
.asc().missing().first()
) )
.isInstanceOf( SearchException.class )
.hasMessageContainingAll( "Missing first on sort with ascending order is not supported." );
}

// Explicit order with missing().use( ... )
if ( !TckConfiguration.get().getBackendFeatures().geoDistanceSortingSupportsConfigurableMissingValues() ) {
assertThatThrownBy( () -> simpleQuery(
dataSetForAsc,
b -> b.distance( fieldPath, CENTER_POINT.latitude(), CENTER_POINT.longitude() )
.asc().missing().use( getSingleValueForMissingUse( BEFORE_DOCUMENT_1_ORDINAL ) )
) )
.isInstanceOf( SearchException.class )
.hasMessageContainingAll( "Missing as on sort is not supported" );
}
}

@Test
Expand Down Expand Up @@ -284,6 +316,10 @@ private String getFieldPath() {
return index.binding().getFieldPath( fieldStructure, fieldType );
}

private GeoPoint getSingleValueForMissingUse(int ordinal) {
return AscendingUniqueDistanceFromCenterValues.INSTANCE.getSingle().get( ordinal );
}

private static class DataSet {
private final TestedFieldStructure fieldStructure;
private final SortMode expectedSortMode;
Expand Down
Expand Up @@ -74,4 +74,8 @@ public boolean supportsTruncateAfterForScroll() {
public boolean supportsExistsForFieldWithoutDocValues(Class<?> fieldType) {
return true;
}

public boolean geoDistanceSortingSupportsConfigurableMissingValues() {
return true;
}
}

0 comments on commit 4891b6b

Please sign in to comment.