Skip to content

Commit

Permalink
HSEARCH-3694 Use GeoPointDistanceComparator for not nested too
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever authored and yrodiere committed Oct 2, 2019
1 parent fad637f commit 126e47f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

public class LuceneGeoPointDistanceComparatorSource extends LuceneFieldComparatorSource {

private static final double MISSING_VALUE_IMPLICIT_DISTANCE_VALUE = Double.POSITIVE_INFINITY;

private final double latitude;
private final double longitude;

Expand All @@ -32,7 +34,7 @@ public LuceneGeoPointDistanceComparatorSource(String nestedDocumentPath, double

@Override
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) {
return new FieldComparator.DoubleComparator( numHits, fieldname, null ) {
return new FieldComparator.DoubleComparator( numHits, fieldname, MISSING_VALUE_IMPLICIT_DISTANCE_VALUE ) {

@Override
protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.lang.invoke.MethodHandles;

import org.apache.lucene.document.LatLonDocValuesField;
import org.apache.lucene.search.SortField;

import org.hibernate.search.backend.lucene.logging.impl.Log;
Expand Down Expand Up @@ -49,11 +48,6 @@ public void order(SortOrder order) {

@Override
public void buildAndContribute(LuceneSearchSortCollector collector) {
if ( nestedDocumentPath == null ) {
collector.collectSortField( LatLonDocValuesField.newDistanceSort( absoluteFieldPath, location.getLatitude(), location.getLongitude() ) );
return;
}

LuceneGeoPointDistanceComparatorSource fieldComparatorSource = new LuceneGeoPointDistanceComparatorSource(
nestedDocumentPath, location.getLatitude(), location.getLongitude() );
SortField sortField = new SortField( absoluteFieldPath, fieldComparatorSource, order == SortOrder.DESC );
Expand Down

0 comments on commit 126e47f

Please sign in to comment.