Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-11601: Improve geodist error message when using with LLPSF.

David Smileyf335ac9bbc52
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 6dd1f12126c..9358c8c82a2 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -134,6 +134,9 @@ Improvements
* SOLR-13702: Some components register twice their metric names (janhoy)
+* SOLR-11601: Improved error message when geodist(llpsf) is used with arguments referring to a LatLonPointSpatialField.
+ (Amrit Sarkar)
+
Bug Fixes
----------------------
diff --git a/solr/core/src/java/org/apache/solr/search/function/distance/GeoDistValueSourceParser.java b/solr/core/src/java/org/apache/solr/search/function/distance/GeoDistValueSourceParser.java
index 0829461d5a5..4f76b8791d8 100644
--- a/solr/core/src/java/org/apache/solr/search/function/distance/GeoDistValueSourceParser.java
+++ b/solr/core/src/java/org/apache/solr/search/function/distance/GeoDistValueSourceParser.java
@@ -26,6 +26,7 @@ import org.apache.lucene.queries.function.valuesource.DoubleConstValueSource;
import org.apache.lucene.queries.function.valuesource.MultiValueSource;
import org.apache.lucene.queries.function.valuesource.VectorValueSource;
import org.apache.lucene.spatial.SpatialStrategy;
+import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.SpatialParams;
import org.apache.solr.schema.AbstractSpatialFieldType;
import org.apache.solr.schema.FieldType;
@@ -51,7 +52,19 @@ public class GeoDistValueSourceParser extends ValueSourceParser {
//note: parseValueSourceList can't handle a field reference to an AbstractSpatialFieldType,
// so those fields are expressly handled via sfield=
- List<ValueSource> sources = fp.parseValueSourceList();
+ List<ValueSource> sources;
+ try {
+ sources = fp.parseValueSourceList();
+ } catch (SolrException e) {
+ if (e.getMessage().equals("A ValueSource isn't directly available from this field. " +
+ "Instead try a query using the distance as the score.")) {
+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "geodist() does not support field names in its arguments " +
+ "when stated fields are solr.LatLonPointSpatialField spatial type, requires sfield param instead");
+ }
+ else {
+ throw e;
+ }
+ }
// "m" is a multi-value source, "x" is a single-value source
// allow (m,m) (m,x,x) (x,x,m) (x,x,x,x)
diff --git a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java
index bc3f0eea83c..ffb2d2eb701 100644
--- a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java
+++ b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java
@@ -370,4 +370,14 @@ public class TestSolr4Spatial2 extends SolrTestCaseJ4 {
assertQ(req(params), "*[count(//doc)=1]", "count(//lst[@name='highlighting']/*)=1");
}
+ @Test
+ public void testErrorHandlingGeodist() throws Exception{
+ assertU(adoc("id", "1", "llp", "32.7693246, -79.9289094"));
+ assertQEx("wrong test exception message","sort param could not be parsed as a query, " +
+ "and is not a field that exists in the index: geodist(llp,47.36667,8.55)",
+ req(
+ "q", "*:*",
+ "sort", "geodist(llp,47.36667,8.55) asc"
+ ), SolrException.ErrorCode.BAD_REQUEST);
+ }
}