Apache Lucene open-source search software
LUCENE-6181: spatial move pointsOnly to superclass and add some getters too.
David Wayne Smiley17d78d072769
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.javaindex f5b41d60758..76db62897ed 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java@@ -21,10 +21,11 @@ import java.util.Iterator;import java.util.Map;import java.util.concurrent.ConcurrentHashMap;+import com.spatial4j.core.shape.Point;+import com.spatial4j.core.shape.Shape;import org.apache.lucene.analysis.TokenStream;import org.apache.lucene.document.Field;import org.apache.lucene.document.FieldType;-import org.apache.lucene.index.FieldInfo;import org.apache.lucene.index.IndexOptions;import org.apache.lucene.queries.function.ValueSource;import org.apache.lucene.spatial.SpatialStrategy;@@ -32,8 +33,6 @@ import org.apache.lucene.spatial.prefix.tree.Cell;import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;import org.apache.lucene.spatial.query.SpatialArgs;import org.apache.lucene.spatial.util.ShapeFieldCacheDistanceValueSource;-import com.spatial4j.core.shape.Point;-import com.spatial4j.core.shape.Shape;/*** An abstract SpatialStrategy based on {@link SpatialPrefixTree}. The two@@ -81,6 +80,7 @@ public abstract class PrefixTreeStrategy extends SpatialStrategy {private final Map<String, PointPrefixTreeFieldCacheProvider> provider = new ConcurrentHashMap<>();protected int defaultFieldValuesArrayLen = 2;protected double distErrPct = SpatialArgs.DEFAULT_DISTERRPCT;// [ 0 TO 0.5 ]+ protected boolean pointsOnly = false;//if true, there are no leavespublic PrefixTreeStrategy(SpatialPrefixTree grid, String fieldName) {super(grid.getSpatialContext(), fieldName);@@ -116,6 +116,16 @@ public abstract class PrefixTreeStrategy extends SpatialStrategy {this.distErrPct = distErrPct;}+ public boolean isPointsOnly() {+ return pointsOnly;+ }++ /** True if only indexed points shall be supported. There are no "leafs" in such a case. See+ * {@link org.apache.lucene.spatial.prefix.IntersectsPrefixTreeFilter#hasIndexedLeaves}. */+ public void setPointsOnly(boolean pointsOnly) {+ this.pointsOnly = pointsOnly;+ }+@Overridepublic Field[] createIndexableFields(Shape shape) {double distErr = SpatialArgs.calcDistanceFromErrPct(shape, distErrPct, ctx);@@ -137,6 +147,9 @@ public abstract class PrefixTreeStrategy extends SpatialStrategy {}protected TokenStream createTokenStream(Shape shape, int detailLevel) {+ if (pointsOnly && shape instanceof Point) {+ throw new IllegalArgumentException("pointsOnly is true yet a point is given for indexing");+ }Iterator<Cell> cells = grid.getTreeCellIterator(shape, detailLevel);return new CellTokenStream().setCells(cells);}diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.javaindex 13fed4a391d..b7353b342d2 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java@@ -17,6 +17,9 @@ package org.apache.lucene.spatial.prefix;* limitations under the License.*/+import java.util.ArrayList;+import java.util.List;+import com.spatial4j.core.shape.Point;import com.spatial4j.core.shape.Shape;import org.apache.lucene.analysis.TokenStream;@@ -29,9 +32,6 @@ import org.apache.lucene.spatial.query.SpatialArgs;import org.apache.lucene.spatial.query.SpatialOperation;import org.apache.lucene.spatial.query.UnsupportedSpatialOperation;-import java.util.ArrayList;-import java.util.List;-/*** A {@link PrefixTreeStrategy} which uses {@link AbstractVisitingPrefixTreeFilter}.* This strategy has support for searching non-point shapes (note: not tested).@@ -56,8 +56,6 @@ public class RecursivePrefixTreeStrategy extends PrefixTreeStrategy {// and a LegacyPrefixTree.protected boolean pruneLeafyBranches = true;- protected boolean pointsOnly = false;//if true, there are no leaves-protected boolean multiOverlappingIndexedShapes = true;public RecursivePrefixTreeStrategy(SpatialPrefixTree grid, String fieldName) {@@ -65,6 +63,10 @@ public class RecursivePrefixTreeStrategy extends PrefixTreeStrategy {prefixGridScanLevel = grid.getMaxLevels() - 4;//TODO this default constant is dependent on the prefix grid size}+ public int getPrefixGridScanLevel() {+ return prefixGridScanLevel;+ }+/*** Sets the grid level [1-maxLevels] at which indexed terms are scanned brute-force* instead of by grid decomposition. By default this is maxLevels - 4. The@@ -77,10 +79,8 @@ public class RecursivePrefixTreeStrategy extends PrefixTreeStrategy {this.prefixGridScanLevel = prefixGridScanLevel;}- /** True if only indexed points shall be supported. There are no "leafs" in such a case. See- * {@link IntersectsPrefixTreeFilter#hasIndexedLeaves}. */- public void setPointsOnly(boolean pointsOnly) {- this.pointsOnly = pointsOnly;+ public boolean isMultiOverlappingIndexedShapes() {+ return multiOverlappingIndexedShapes;}/** See {@link ContainsPrefixTreeFilter#multiOverlappingIndexedShapes}. */@@ -88,6 +88,10 @@ public class RecursivePrefixTreeStrategy extends PrefixTreeStrategy {this.multiOverlappingIndexedShapes = multiOverlappingIndexedShapes;}+ public boolean isPruneLeafyBranches() {+ return pruneLeafyBranches;+ }+/** An optional hint affecting non-point shapes: it will* simplify/aggregate sets of complete leaves in a cell to its parent, resulting in ~20-25%* fewer indexed cells. However, it will likely be removed in the future. (default=true)