Apache Solr open-source search software
SOLR-18355: Remove deprecated GeohashFunction/GeohashHaversineFunction (#4788)
Serhiy Bzhezytskyy558c49062622
diff --git a/changelog/unreleased/SOLR-18355-remove-geohashfunction.yml b/changelog/unreleased/SOLR-18355-remove-geohashfunction.ymlnew file mode 100644index 00000000000..c1af6e95f93--- /dev/null+++ b/changelog/unreleased/SOLR-18355-remove-geohashfunction.yml@@ -0,0 +1,10 @@+title: >+ Removed the deprecated `geohash(lat,lon)` and `ghhsin(geohash1,geohash2,radius)` function queries+ (`GeohashFunction`/`GeohashHaversineFunction`), deprecated without a replacement since 9.0. Use `hsin`/`geodist`+ with raw latitude/longitude value sources instead of encoding to a geohash string first.+type: removed+authors:+ - name: Serhiy Bzhezytskyy+links:+ - name: SOLR-18355+ url: https://issues.apache.org/jira/browse/SOLR-18355diff --git a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.javaindex 943a1239b21..ba71d147fc5 100644--- a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java+++ b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java@@ -109,8 +109,6 @@ import org.apache.solr.search.function.OrdFieldSource;import org.apache.solr.search.function.ReverseOrdFieldSource;import org.apache.solr.search.function.SolrComparisonBoolFunction;import org.apache.solr.search.function.distance.GeoDistValueSourceParser;-import org.apache.solr.search.function.distance.GeohashFunction;-import org.apache.solr.search.function.distance.GeohashHaversineFunction;import org.apache.solr.search.function.distance.HaversineFunction;import org.apache.solr.search.function.distance.SquaredEuclideanFunction;import org.apache.solr.search.function.distance.StringDistanceFunction;@@ -460,32 +458,6 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {}});- addParser(- "ghhsin",- new ValueSourceParser() {- @Override- public ValueSource parse(FunctionQParser fp) throws SyntaxError {- double radius = fp.parseDouble();-- ValueSource gh1 = fp.parseValueSource();- ValueSource gh2 = fp.parseValueSource();-- return new GeohashHaversineFunction(gh1, gh2, radius);- }- });-- addParser(- "geohash",- new ValueSourceParser() {- @Override- public ValueSource parse(FunctionQParser fp) throws SyntaxError {-- ValueSource lat = fp.parseValueSource();- ValueSource lon = fp.parseValueSource();-- return new GeohashFunction(lat, lon);- }- });addParser("strdist",new ValueSourceParser() {diff --git a/solr/core/src/java/org/apache/solr/search/function/distance/GeohashFunction.java b/solr/core/src/java/org/apache/solr/search/function/distance/GeohashFunction.javadeleted file mode 100644index 730b6657186..00000000000--- a/solr/core/src/java/org/apache/solr/search/function/distance/GeohashFunction.java+++ /dev/null@@ -1,96 +0,0 @@-/*- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */-package org.apache.solr.search.function.distance;--import java.io.IOException;-import java.util.Map;-import org.apache.lucene.index.LeafReaderContext;-import org.apache.lucene.queries.function.FunctionValues;-import org.apache.lucene.queries.function.ValueSource;-import org.locationtech.spatial4j.io.GeohashUtils;--/**- * Takes in a latitude and longitude ValueSource and produces a GeoHash.- *- * <p>Ex: geohash(lat, lon)- *- * <p>Note, there is no reciprocal function for this.- */-@Deprecated-public class GeohashFunction extends ValueSource {- protected ValueSource lat, lon;-- public GeohashFunction(ValueSource lat, ValueSource lon) {- this.lat = lat;- this.lon = lon;- }-- protected String name() {- return "geohash";- }-- @Override- public FunctionValues getValues(Map<Object, Object> context, LeafReaderContext readerContext)- throws IOException {- final FunctionValues latDV = lat.getValues(context, readerContext);- final FunctionValues lonDV = lon.getValues(context, readerContext);-- return new FunctionValues() {-- @Override- public String strVal(int doc) throws IOException {- return GeohashUtils.encodeLatLon(latDV.doubleVal(doc), lonDV.doubleVal(doc));- }-- @Override- public String toString(int doc) throws IOException {- StringBuilder sb = new StringBuilder();- sb.append(name()).append('(');- sb.append(latDV.toString(doc)).append(',').append(lonDV.toString(doc));- sb.append(')');- return sb.toString();- }- };- }-- @Override- public boolean equals(Object o) {- if (this == o) return true;- if (!(o instanceof GeohashFunction that)) return false;-- if (!lat.equals(that.lat)) return false;- if (!lon.equals(that.lon)) return false;-- return true;- }-- @Override- public int hashCode() {- int result = lat.hashCode();- result = 29 * result - lon.hashCode();- return result;- }-- @Override- public String description() {- StringBuilder sb = new StringBuilder();- sb.append(name()).append('(');- sb.append(lat).append(',').append(lon);- sb.append(')');- return sb.toString();- }-}diff --git a/solr/core/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java b/solr/core/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.javadeleted file mode 100644index 7c13ab9d56e..00000000000--- a/solr/core/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java+++ /dev/null@@ -1,134 +0,0 @@-/*- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */-package org.apache.solr.search.function.distance;--import java.io.IOException;-import java.util.Map;-import java.util.Objects;-import org.apache.lucene.index.LeafReaderContext;-import org.apache.lucene.queries.function.FunctionValues;-import org.apache.lucene.queries.function.ValueSource;-import org.apache.lucene.queries.function.docvalues.DoubleDocValues;-import org.apache.lucene.search.IndexSearcher;-import org.locationtech.spatial4j.context.SpatialContext;-import org.locationtech.spatial4j.distance.DistanceUtils;-import org.locationtech.spatial4j.distance.GeodesicSphereDistCalc;-import org.locationtech.spatial4j.io.GeohashUtils;-import org.locationtech.spatial4j.shape.Point;--/**- * Calculate the Haversine distance between two geo hash codes.- *- * <p>Ex: ghhsin(ValueSource, ValueSource, radius)- *- * @see org.apache.solr.search.function.distance.HaversineFunction for more details on the- * implementation- */-@Deprecated-public class GeohashHaversineFunction extends ValueSource {-- private final ValueSource geoHash1, geoHash2;- private final SpatialContext ctx;- private final double degreesToDist;-- public GeohashHaversineFunction(ValueSource geoHash1, ValueSource geoHash2, double radius) {- this.geoHash1 = geoHash1;- this.geoHash2 = geoHash2;- this.degreesToDist = DistanceUtils.degrees2Dist(1, radius);- this.ctx = SpatialContext.GEO;- assert this.ctx.getDistCalc() instanceof GeodesicSphereDistCalc.Haversine;- }-- protected String name() {- return "ghhsin";- }-- @Override- public FunctionValues getValues(Map<Object, Object> context, LeafReaderContext readerContext)- throws IOException {- final FunctionValues gh1DV = geoHash1.getValues(context, readerContext);- final FunctionValues gh2DV = geoHash2.getValues(context, readerContext);-- return new DoubleDocValues(this) {- @Override- public double doubleVal(int doc) throws IOException {- return distance(doc, gh1DV, gh2DV);- }-- @Override- public String toString(int doc) throws IOException {- StringBuilder sb = new StringBuilder();- sb.append(name()).append('(');- sb.append(gh1DV.toString(doc)).append(',').append(gh2DV.toString(doc));- sb.append(')');- return sb.toString();- }- };- }-- protected double distance(int doc, FunctionValues gh1DV, FunctionValues gh2DV)- throws IOException {- double result = 0;- String h1 = gh1DV.strVal(doc);- String h2 = gh2DV.strVal(doc);- if (h1 != null && h2 != null && h1.equals(h2) == false) {- // TODO: If one of the hashes is a literal value source, seems like we could cache it- // and avoid decoding every time- Point p1 = GeohashUtils.decode(h1, ctx);- Point p2 = GeohashUtils.decode(h2, ctx);- result = ctx.getDistCalc().distance(p1, p2) * degreesToDist;- } else if (h1 == null || h2 == null) {- result = Double.MAX_VALUE;- }- return result;- }-- @Override- public void createWeight(Map<Object, Object> context, IndexSearcher searcher) throws IOException {- geoHash1.createWeight(context, searcher);- geoHash2.createWeight(context, searcher);- }-- @Override- public boolean equals(Object o) {- if (!(o instanceof GeohashHaversineFunction other)) return false;- return Objects.equals(this.name(), other.name())- && Objects.equals(geoHash1, other.geoHash1)- && Objects.equals(geoHash2, other.geoHash2)- && (degreesToDist == other.degreesToDist);- }-- @Override- public int hashCode() {- int result;- result = geoHash1.hashCode();- result = 31 * result + geoHash2.hashCode();- result = 31 * result + name().hashCode();- long temp = Double.doubleToRawLongBits(degreesToDist);- result = 31 * result + (int) (temp ^ (temp >>> 32));- return result;- }-- @Override- public String description() {- StringBuilder sb = new StringBuilder();- sb.append(name()).append('(');- sb.append(geoHash1).append(',').append(geoHash2);- sb.append(')');- return sb.toString();- }-}diff --git a/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java b/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.javaindex 9b94f2a2542..1a39024c946 100644--- a/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java+++ b/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java@@ -1123,16 +1123,6 @@ public class QueryEqualityTest extends SolrTestCaseJ4 {assertFuncEquals("hsin(45,true,0,0,45,45)");}- public void testFuncGhhsin() throws Exception {- assertFuncEquals(- "ghhsin(45,id,'asdf')",- "ghhsin(45,field(id),'asdf')"); // "id" is just a single-valued string field- }-- public void testFuncGeohash() throws Exception {- assertFuncEquals("geohash(45,99)");- }-public void testFuncDist() throws Exception {assertFuncEquals("dist(2,45,99,101,111)", "dist(2,vector(45,99),vector(101,111))");}