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/02/26 05:04:48 UTC

svn commit: r1450011 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/spatial/ lucene/spatial/src/java/org/apache/lucene/spatial/prefix/ lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/ lucene/spatial/src/test/org/apache/lucene/spat...

Author: dsmiley
Date: Tue Feb 26 04:04:47 2013
New Revision: 1450011

URL: http://svn.apache.org/r1450011
Log:
LUCENE-4794 Spatial PrefixTree traversal abstraction

Added:
    lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/AbstractPrefixTreeFilter.java
      - copied unchanged from r1450010, lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/AbstractPrefixTreeFilter.java
    lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/AbstractVisitingPrefixTreeFilter.java
      - copied unchanged from r1450010, lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/AbstractVisitingPrefixTreeFilter.java
    lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/IntersectsPrefixTreeFilter.java
      - copied unchanged from r1450010, lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/IntersectsPrefixTreeFilter.java
    lucene/dev/branches/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java
      - copied, changed from r1450010, lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java
Removed:
    lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeFilter.java
Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/lucene/spatial/   (props changed)
    lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java
    lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/Node.java

Modified: lucene/dev/branches/branch_4x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/CHANGES.txt?rev=1450011&r1=1450010&r2=1450011&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Tue Feb 26 04:04:47 2013
@@ -103,6 +103,10 @@ Optimizations
 * LUCENE-4792: Reduction of the memory required to build the doc ID maps used
   when merging segments. (Adrien Grand)
 
+* LUCENE-4794: Spatial RecursivePrefixTreeStrategy's search filter: Skip calls
+  to termsEnum.seek() when the next term is known to follow the current cell.
+  (David Smiley)
+
 New Features
 
 * LUCENE-4686: New specialized DGapVInt8IntEncoder for facets (now the 
@@ -183,6 +187,9 @@ API Changes
   a boolean indicating whether a new reference was in fact opened, and
   a new beforeRefresh method notifies you when a refresh attempt is
   starting.  (Robert Muir, Mike McCandless)
+
+* LUCENE-4794: Spatial RecursivePrefixTreeFilter replaced by
+  IntersectsPrefixTreeFilter and some extensible base classes. (David Smiley)
   
 Bug Fixes
 

Modified: lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java?rev=1450011&r1=1450010&r2=1450011&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java (original)
+++ lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java Tue Feb 26 04:04:47 2013
@@ -25,7 +25,7 @@ import org.apache.lucene.spatial.query.S
 import org.apache.lucene.spatial.query.UnsupportedSpatialOperation;
 
 /**
- * A {@link PrefixTreeStrategy} which uses {@link RecursivePrefixTreeFilter}.
+ * A {@link PrefixTreeStrategy} which uses {@link AbstractVisitingPrefixTreeFilter}.
  * This strategy has support for searching non-point shapes (note: not tested).
  * Even a query shape with distErrPct=0 (fully precise to the grid) should have
  * good performance for typical data, unless there is a lot of indexed data
@@ -70,8 +70,9 @@ public class RecursivePrefixTreeStrategy
 
     int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct));
 
-    return new RecursivePrefixTreeFilter(
-        getFieldName(), grid, shape, prefixGridScanLevel, detailLevel);
+    return new IntersectsPrefixTreeFilter(
+        shape, getFieldName(), grid, detailLevel, prefixGridScanLevel,
+        true);//hasIndexedLeaves
   }
 }
 

Modified: lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/Node.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/Node.java?rev=1450011&r1=1450010&r2=1450011&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/Node.java (original)
+++ lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/Node.java Tue Feb 26 04:04:47 2013
@@ -1,3 +1,5 @@
+package org.apache.lucene.spatial.prefix.tree;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -15,8 +17,6 @@
  * limitations under the License.
  */
 
-package org.apache.lucene.spatial.prefix.tree;
-
 import com.spatial4j.core.shape.Point;
 import com.spatial4j.core.shape.Shape;
 import com.spatial4j.core.shape.SpatialRelation;
@@ -27,7 +27,8 @@ import java.util.Collections;
 import java.util.List;
 
 /**
- * Represents a grid cell. These are not necessarily thread-safe, although new Cell("") (world cell) must be.
+ * Represents a grid cell. These are not necessarily thread-safe, although new
+ * Cell("") (world cell) must be.
  *
  * @lucene.experimental
  */
@@ -44,13 +45,19 @@ public abstract class Node implements Co
 
   private String token;//this is the only part of equality
 
-  /** When set via getSubCells(filter), it is the relationship between this
-   * cell and the given shape filter.  If set via setLeaf() (to WITHIN), it is
-   * meant to indicate no further sub-cells are going to be provided because
-   * maxLevels or a detailLevel is hit. It's always null for points.
+  /**
+   * When set via getSubCells(filter), it is the relationship between this cell
+   * and the given shape filter.
    */
   protected SpatialRelation shapeRel;
 
+  /**
+   * Always false for points. Otherwise, indicate no further sub-cells are going
+   * to be provided because shapeRel is WITHIN or maxLevels or a detailLevel is
+   * hit.
+   */
+  protected boolean leaf;
+
   protected Node(String token) {
     this.token = token;
     if (token.length() > 0 && token.charAt(token.length() - 1) == (char) LEAF_BYTE) {
@@ -96,12 +103,13 @@ public abstract class Node implements Co
    * further cells with this prefix for the shape (always true at maxLevels).
    */
   public boolean isLeaf() {
-    return shapeRel == SpatialRelation.WITHIN;
+    return leaf;
   }
 
+  /** Note: not supported at level 0. */
   public void setLeaf() {
     assert getLevel() != 0;
-    shapeRel = SpatialRelation.WITHIN;
+    leaf = true;
   }
 
   /**
@@ -139,12 +147,11 @@ public abstract class Node implements Co
 
   /**
    * Like {@link #getSubCells()} but with the results filtered by a shape. If
-   * that shape is a {@link com.spatial4j.core.shape.Point} then it
-   * must call {@link #getSubCell(com.spatial4j.core.shape.Point)}.
-   * The returned cells should have their {@link Node#shapeRel} set to their
-   * relation with {@code shapeFilter} for non-point. As such,
-   * {@link org.apache.lucene.spatial.prefix.tree.Node#isLeaf()} should be
-   * accurate.
+   * that shape is a {@link com.spatial4j.core.shape.Point} then it must call
+   * {@link #getSubCell(com.spatial4j.core.shape.Point)}. The returned cells
+   * should have {@link Node#getShapeRel()} set to their relation with {@code
+   * shapeFilter}. In addition, {@link org.apache.lucene.spatial.prefix.tree.Node#isLeaf()}
+   * must be true when that relation is WITHIN.
    * <p/>
    * Precondition: Never called when getLevel() == maxLevel.
    *
@@ -154,29 +161,35 @@ public abstract class Node implements Co
   public Collection<Node> getSubCells(Shape shapeFilter) {
     //Note: Higher-performing subclasses might override to consider the shape filter to generate fewer cells.
     if (shapeFilter instanceof Point) {
-      return Collections.singleton(getSubCell((Point) shapeFilter));
+      Node subCell = getSubCell((Point) shapeFilter);
+      subCell.shapeRel = SpatialRelation.CONTAINS;
+      return Collections.singletonList(subCell);
     }
     Collection<Node> cells = getSubCells();
 
     if (shapeFilter == null) {
       return cells;
     }
-    List<Node> copy = new ArrayList<Node>(cells.size());//copy since cells contractually isn't modifiable
+
+    //TODO change API to return a filtering iterator
+    List<Node> copy = new ArrayList<Node>(cells.size());
     for (Node cell : cells) {
       SpatialRelation rel = cell.getShape().relate(shapeFilter);
       if (rel == SpatialRelation.DISJOINT)
         continue;
       cell.shapeRel = rel;
+      if (rel == SpatialRelation.WITHIN)
+        cell.setLeaf();
       copy.add(cell);
     }
-    cells = copy;
-    return cells;
+    return copy;
   }
 
   /**
-   * Performant implementations are expected to implement this efficiently by considering the current
-   * cell's boundary.
-   * Precondition: Never called when getLevel() == maxLevel.
+   * Performant implementations are expected to implement this efficiently by
+   * considering the current cell's boundary. Precondition: Never called when
+   * getLevel() == maxLevel.
+   * <p/>
    * Precondition: this.getShape().relate(p) != DISJOINT.
    */
   public abstract Node getSubCell(Point p);
@@ -187,7 +200,7 @@ public abstract class Node implements Co
    * Gets the cells at the next grid cell level that cover this cell.
    * Precondition: Never called when getLevel() == maxLevel.
    *
-   * @return A set of cells (no dups), sorted. Not Modifiable.
+   * @return A set of cells (no dups), sorted, modifiable, not empty, not null.
    */
   protected abstract Collection<Node> getSubCells();
 

Copied: lucene/dev/branches/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java (from r1450010, lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java?p2=lucene/dev/branches/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java&p1=lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java&r1=1450010&r2=1450011&rev=1450011&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java Tue Feb 26 04:04:47 2013
@@ -19,7 +19,6 @@ package org.apache.lucene.spatial;
 
 import com.spatial4j.core.context.SpatialContext;
 import com.spatial4j.core.shape.Shape;
-import org.apache.lucene.spatial.bbox.BBoxStrategy;
 import org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy;
 import org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy;
 import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;
@@ -63,12 +62,6 @@ public class QueryEqualsHashCodeTest ext
         return new PointVectorStrategy(ctx, "pointvector").makeQuery(args);
       }
     });
-    generators.add(new ObjGenerator() {
-      @Override
-      public Object gen(SpatialArgs args) {
-        return new BBoxStrategy(ctx, "bbox").makeQuery(args);
-      }
-    });
 
     for (ObjGenerator generator : generators) {
       testStratQueryEqualsHashcode(args1, args2, generator);