SOLR-4255: add spatial filter=false local-param option

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1429466 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David Wayne Smiley 2013-01-06 06:01:58 +00:00
parent 643fab0b82
commit 9c5d4ff5cb
2 changed files with 23 additions and 1 deletions

View File

@ -64,6 +64,11 @@ public abstract class AbstractSpatialFieldType<T extends SpatialStrategy> extend
/** A local-param with one of "none" (default), "distance", or "recipDistance". */
public static final String SCORE_PARAM = "score";
/** A local-param boolean that can be set to false to only return the
* FunctionQuery (score), and thus not do filtering.
*/
public static final String FILTER_PARAM = "filter";
protected final Logger log = LoggerFactory.getLogger( getClass() );
protected SpatialContext ctx;
@ -249,9 +254,13 @@ public abstract class AbstractSpatialFieldType<T extends SpatialStrategy> extend
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))
return functionQuery;
Filter filter = strategy.makeFilter(spatialArgs);
return new FilteredQuery(new FunctionQuery(valueSource), filter);
return new FilteredQuery(functionQuery, filter);
}
/**

View File

@ -263,6 +263,19 @@ public class TestSolr4Spatial extends SolrTestCaseJ4 {
, "/response/docs/[1]/score==0.19970943"
);
//score by distance and don't filter
assertJQ(req(
//circle radius is small and shouldn't match either, but we disable filtering
"q", "{! score=distance filter=false}"+fieldName +":\"Intersects(Circle(3,4 d=0.000001))\"",
"fl","id,score",
"sort","score asc")//want ascending due to increasing distance
, 1e-3
, "/response/docs/[0]/id=='100'"
, "/response/docs/[0]/score==2.827493"
, "/response/docs/[1]/id=='101'"
, "/response/docs/[1]/score==5.089807"
);
//query again with the query point closer to #101, and check the new ordering
assertJQ(req(
"q", "{! score=distance}"+fieldName +":\"Intersects(Circle(4,0 d=9))\"",