You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2014/07/09 04:24:19 UTC

svn commit: r1608991 - /lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java

Author: dsmiley
Date: Wed Jul  9 02:24:19 2014
New Revision: 1608991

URL: http://svn.apache.org/r1608991
Log:
SOLR-6183: AbstractSpatialFieldType: refactor getValueSourceFromSpatialArgs out of getQueryFromSpatialArgs

Modified:
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java?rev=1608991&r1=1608990&r2=1608991&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java Wed Jul  9 02:24:19 2014
@@ -268,8 +268,12 @@ public abstract class AbstractSpatialFie
     T 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 AbstractSpatialFie
       return 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 AbstractSpatialFie
     return 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)}.