GeoDistanceSortField extends SortField { public GeoDistanceSortField(String field, Boolean reverse, double latitude, double longitude) { super(reverse); if (field == null || StringUtils.isBlank(field)) { throw new IndexException("Field name required"); } this.field = field; this.latitude = GeospatialUtils.checkLatitude("latitude", latitude); this.longitude = GeospatialUtils.checkLongitude("longitude", longitude); } GeoDistanceSortField(String field, Boolean reverse, double latitude, double longitude); @Override org.apache.lucene.search.SortField sortField(Schema schema); Set<String> postProcessingFields(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); final String field; final double latitude; final double longitude; }
@Test public void testGeoDistanceSortField() { Schema schema = schema().mapper("field", geoPointMapper("latitude", "longitude")).build(); GeoDistanceSortField sortField = new GeoDistanceSortField("field", false, 0.0, 0.0); org.apache.lucene.search.SortField luceneSortField = sortField.sortField(schema); assertNotNull("SortField is not created", luceneSortField); assertFalse("SortField reverse is wrong", luceneSortField.getReverse()); }