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 2013/01/06 07:51:02 UTC

svn commit: r1429472 - in /lucene/dev/branches/branch_4x: ./ solr/ solr/CHANGES.txt solr/core/ solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java

Author: dsmiley
Date: Sun Jan  6 06:51:01 2013
New Revision: 1429472

URL: http://svn.apache.org/viewvc?rev=1429472&view=rev
Log:
SOLR-4255: add spatial filter=false local-param option

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/CHANGES.txt
    lucene/dev/branches/branch_4x/solr/core/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java

Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1429472&r1=1429471&r2=1429472&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Sun Jan  6 06:51:01 2013
@@ -171,6 +171,10 @@ New Features
 
 * SOLR-4271: Add support for PostingsHighlighter.  (Robert Muir)
 
+* SOLR-4255: The new Solr 4 spatial fields now have a 'filter' boolean local-param
+  that can be set to false to not filter. Its useful when there is already a spatial
+  filter query but you also need to sort or boost by distance. (David Smiley)
+
 Optimizations
 ----------------------
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java?rev=1429472&r1=1429471&r2=1429472&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java Sun Jan  6 06:51:01 2013
@@ -64,6 +64,11 @@ public abstract class AbstractSpatialFie
 
   /** 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 AbstractSpatialFie
       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);
   }
 
   /**

Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java?rev=1429472&r1=1429471&r2=1429472&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java Sun Jan  6 06:51:01 2013
@@ -263,6 +263,19 @@ public class TestSolr4Spatial extends So
         , "/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))\"",