mirror of https://github.com/apache/lucene.git
SOLR-11601: Improve geodist error message when using with LLPSF.
This commit is contained in:
parent
180f6d2ec9
commit
f335ac9bbc
|
@ -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
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue