Apache Lucene open-source search software
SOLR-6183: AbstractSpatialFieldType: refactor getValueSourceFromSpatialArgs out of getQueryFromSpatialArgs
David Wayne Smileyd1d810128975
diff --git a/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java b/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.javaindex 3ae7e3a1bef..4ba31ddfcad 100644--- a/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java+++ b/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java@@ -268,8 +268,12 @@ public abstract class AbstractSpatialFieldType<T extends SpatialStrategy> extendT strategy = getStrategy(field.getName());SolrParams localParams = parser.getLocalParams();- String score = (localParams == null ? null : localParams.get(SCORE_PARAM));- if (score == null || "none".equals(score) || "".equals(score)) {+ String scoreParam = (localParams == null ? null : localParams.get(SCORE_PARAM));++ //We get the valueSource for the score then the filter and combine them.++ ValueSource valueSource = getValueSourceFromSpatialArgs(parser, field, spatialArgs, scoreParam, strategy);+ if (valueSource == null) {//FYI Solr FieldType doesn't have a getFilter(). We'll always grab// getQuery() but it's possible a strategy has a more efficient getFilter// that could be wrapped -- no way to know.@@ -277,16 +281,6 @@ public abstract class AbstractSpatialFieldType<T extends SpatialStrategy> extendreturn strategy.makeQuery(spatialArgs); //ConstantScoreQuery}- //We get the valueSource for the score then the filter and combine them.- ValueSource valueSource;- if ("distance".equals(score)) {- double multiplier = 1.0;//TODO support units=kilometers- valueSource = strategy.makeDistanceValueSource(spatialArgs.getShape().getCenter(), multiplier);- } else if ("recipDistance".equals(score)) {- valueSource = strategy.makeRecipDistanceValueSource(spatialArgs.getShape());- } else {- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'score' local-param must be one of 'none', 'distance', or 'recipDistance'");- }FunctionQuery functionQuery = new FunctionQuery(valueSource);if (localParams != null && !localParams.getBool(FILTER_PARAM, true))@@ -296,6 +290,19 @@ public abstract class AbstractSpatialFieldType<T extends SpatialStrategy> extendreturn new FilteredQuery(functionQuery, filter);}+ protected ValueSource getValueSourceFromSpatialArgs(QParser parser, SchemaField field, SpatialArgs spatialArgs, String score, T strategy) {+ if (score == null || "none".equals(score) || "".equals(score)) {+ return null;+ } else if ("distance".equals(score)) {+ double multiplier = 1.0;//TODO support units=kilometers+ return strategy.makeDistanceValueSource(spatialArgs.getShape().getCenter(), multiplier);+ } else if ("recipDistance".equals(score)) {+ return strategy.makeRecipDistanceValueSource(spatialArgs.getShape());+ } else {+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'score' local-param must be one of 'none', 'distance', or 'recipDistance'");+ }+ }+/*** Gets the cached strategy for this field, creating it if necessary* via {@link #newSpatialStrategy(String)}.