mirror of https://github.com/apache/lucene.git
LUCENE-6181: spatial move pointsOnly to superclass and add some getters too.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1652147 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
02e4a111d3
commit
17d78d0727
|
@ -21,10 +21,11 @@ import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
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.analysis.TokenStream;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.FieldType;
|
import org.apache.lucene.document.FieldType;
|
||||||
import org.apache.lucene.index.FieldInfo;
|
|
||||||
import org.apache.lucene.index.IndexOptions;
|
import org.apache.lucene.index.IndexOptions;
|
||||||
import org.apache.lucene.queries.function.ValueSource;
|
import org.apache.lucene.queries.function.ValueSource;
|
||||||
import org.apache.lucene.spatial.SpatialStrategy;
|
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.prefix.tree.SpatialPrefixTree;
|
||||||
import org.apache.lucene.spatial.query.SpatialArgs;
|
import org.apache.lucene.spatial.query.SpatialArgs;
|
||||||
import org.apache.lucene.spatial.util.ShapeFieldCacheDistanceValueSource;
|
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
|
* 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<>();
|
private final Map<String, PointPrefixTreeFieldCacheProvider> provider = new ConcurrentHashMap<>();
|
||||||
protected int defaultFieldValuesArrayLen = 2;
|
protected int defaultFieldValuesArrayLen = 2;
|
||||||
protected double distErrPct = SpatialArgs.DEFAULT_DISTERRPCT;// [ 0 TO 0.5 ]
|
protected double distErrPct = SpatialArgs.DEFAULT_DISTERRPCT;// [ 0 TO 0.5 ]
|
||||||
|
protected boolean pointsOnly = false;//if true, there are no leaves
|
||||||
|
|
||||||
public PrefixTreeStrategy(SpatialPrefixTree grid, String fieldName) {
|
public PrefixTreeStrategy(SpatialPrefixTree grid, String fieldName) {
|
||||||
super(grid.getSpatialContext(), fieldName);
|
super(grid.getSpatialContext(), fieldName);
|
||||||
|
@ -116,6 +116,16 @@ public abstract class PrefixTreeStrategy extends SpatialStrategy {
|
||||||
this.distErrPct = distErrPct;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Field[] createIndexableFields(Shape shape) {
|
public Field[] createIndexableFields(Shape shape) {
|
||||||
double distErr = SpatialArgs.calcDistanceFromErrPct(shape, distErrPct, ctx);
|
double distErr = SpatialArgs.calcDistanceFromErrPct(shape, distErrPct, ctx);
|
||||||
|
@ -137,6 +147,9 @@ public abstract class PrefixTreeStrategy extends SpatialStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TokenStream createTokenStream(Shape shape, int detailLevel) {
|
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);
|
Iterator<Cell> cells = grid.getTreeCellIterator(shape, detailLevel);
|
||||||
return new CellTokenStream().setCells(cells);
|
return new CellTokenStream().setCells(cells);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@ package org.apache.lucene.spatial.prefix;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.spatial4j.core.shape.Point;
|
import com.spatial4j.core.shape.Point;
|
||||||
import com.spatial4j.core.shape.Shape;
|
import com.spatial4j.core.shape.Shape;
|
||||||
import org.apache.lucene.analysis.TokenStream;
|
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.SpatialOperation;
|
||||||
import org.apache.lucene.spatial.query.UnsupportedSpatialOperation;
|
import org.apache.lucene.spatial.query.UnsupportedSpatialOperation;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link PrefixTreeStrategy} which uses {@link AbstractVisitingPrefixTreeFilter}.
|
* A {@link PrefixTreeStrategy} which uses {@link AbstractVisitingPrefixTreeFilter}.
|
||||||
* This strategy has support for searching non-point shapes (note: not tested).
|
* This strategy has support for searching non-point shapes (note: not tested).
|
||||||
|
@ -56,8 +56,6 @@ public class RecursivePrefixTreeStrategy extends PrefixTreeStrategy {
|
||||||
// and a LegacyPrefixTree.
|
// and a LegacyPrefixTree.
|
||||||
protected boolean pruneLeafyBranches = true;
|
protected boolean pruneLeafyBranches = true;
|
||||||
|
|
||||||
protected boolean pointsOnly = false;//if true, there are no leaves
|
|
||||||
|
|
||||||
protected boolean multiOverlappingIndexedShapes = true;
|
protected boolean multiOverlappingIndexedShapes = true;
|
||||||
|
|
||||||
public RecursivePrefixTreeStrategy(SpatialPrefixTree grid, String fieldName) {
|
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
|
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
|
* 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
|
* instead of by grid decomposition. By default this is maxLevels - 4. The
|
||||||
|
@ -77,10 +79,8 @@ public class RecursivePrefixTreeStrategy extends PrefixTreeStrategy {
|
||||||
this.prefixGridScanLevel = prefixGridScanLevel;
|
this.prefixGridScanLevel = prefixGridScanLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** True if only indexed points shall be supported. There are no "leafs" in such a case. See
|
public boolean isMultiOverlappingIndexedShapes() {
|
||||||
* {@link IntersectsPrefixTreeFilter#hasIndexedLeaves}. */
|
return multiOverlappingIndexedShapes;
|
||||||
public void setPointsOnly(boolean pointsOnly) {
|
|
||||||
this.pointsOnly = pointsOnly;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** See {@link ContainsPrefixTreeFilter#multiOverlappingIndexedShapes}. */
|
/** See {@link ContainsPrefixTreeFilter#multiOverlappingIndexedShapes}. */
|
||||||
|
@ -88,6 +88,10 @@ public class RecursivePrefixTreeStrategy extends PrefixTreeStrategy {
|
||||||
this.multiOverlappingIndexedShapes = multiOverlappingIndexedShapes;
|
this.multiOverlappingIndexedShapes = multiOverlappingIndexedShapes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPruneLeafyBranches() {
|
||||||
|
return pruneLeafyBranches;
|
||||||
|
}
|
||||||
|
|
||||||
/** An optional hint affecting non-point shapes: it will
|
/** 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%
|
* 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)
|
* fewer indexed cells. However, it will likely be removed in the future. (default=true)
|
||||||
|
|
Loading…
Reference in New Issue