mirror of https://github.com/apache/lucene.git
SOLR-6183: AbstractSpatialFieldType: refactor getValueSourceFromSpatialArgs out of getQueryFromSpatialArgs
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1608991 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
99f135848a
commit
d1d8101289
|
@ -268,8 +268,12 @@ public abstract class AbstractSpatialFieldType<T extends SpatialStrategy> extend
|
|||
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 AbstractSpatialFieldType<T extends SpatialStrategy> extend
|
|||
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 AbstractSpatialFieldType<T extends SpatialStrategy> extend
|
|||
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)}.
|
||||
|
|
Loading…
Reference in New Issue