This is an automated email from the ASF dual-hosted git repository.
epugh pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_10x by this push:
new 44d7d248534 SOLR-18355: Remove deprecated
GeohashFunction/GeohashHaversineFunction (#4788)
44d7d248534 is described below
commit 44d7d24853482f9c20fbec7923958ab8b8e1c5c1
Author: Serhiy Bzhezytskyy <[email protected]>
AuthorDate: Tue Aug 25 01:48:13 2026 +0300
SOLR-18355: Remove deprecated GeohashFunction/GeohashHaversineFunction
(#4788)
(cherry picked from commit 558c49062622d553e61d9e7e53d3535f67f5c0b3)
---
.../SOLR-18355-remove-geohashfunction.yml | 10 ++
.../org/apache/solr/search/ValueSourceParser.java | 28 -----
.../search/function/distance/GeohashFunction.java | 96 ---------------
.../distance/GeohashHaversineFunction.java | 134 ---------------------
.../org/apache/solr/search/QueryEqualityTest.java | 10 --
5 files changed, 10 insertions(+), 268 deletions(-)
diff --git a/changelog/unreleased/SOLR-18355-remove-geohashfunction.yml
b/changelog/unreleased/SOLR-18355-remove-geohashfunction.yml
new file mode 100644
index 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-18355
diff --git a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
index 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.java
deleted file mode 100644
index 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.java
deleted file mode 100644
index 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.java
index 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))");
}