public abstract class NumberRangePrefixTree extends SpatialPrefixTree
Why might you use this instead of Lucene's built-in integer/long support? Here are some reasons with features based on code in this class, or are possible based on this class but require a subclass to fully realize it.
BigDecimal
.Shape
s
created by the methods on this class, not from any SpatialContext
.NumberRangePrefixTreeStrategy
,
LUCENE-5648Modifier and Type | Class and Description |
---|---|
protected class |
NumberRangePrefixTree.NRCell
Most of the PrefixTree implementation is in this one class, which is both
the Cell, the CellIterator, and the Shape to reduce object allocation.
|
static interface |
NumberRangePrefixTree.NRShape
Base interface for
Shape s this prefix tree supports. |
class |
NumberRangePrefixTree.SpanUnitsNRShape
A range Shape; based on a pair of
NumberRangePrefixTree.UnitNRShape . |
static interface |
NumberRangePrefixTree.UnitNRShape
A unit value Shape implemented as a stack of numbers, one for each level in the prefix tree.
|
Modifier and Type | Field and Description |
---|---|
protected int[] |
levelByTermLen |
protected int[] |
maxSubCellsByLevel |
protected int |
maxTermLen |
protected int[] |
termLenByLevel |
ctx, maxLevels
Modifier | Constructor and Description |
---|---|
protected |
NumberRangePrefixTree(int[] maxSubCellsByLevel) |
Modifier and Type | Method and Description |
---|---|
protected static int |
comparePrefix(NumberRangePrefixTree.UnitNRShape a,
NumberRangePrefixTree.UnitNRShape b)
Compares a to b, returning less than 0, 0, or greater than 0, if a is less than, equal to, or
greater than b, respectively, up to their common prefix (i.e.
|
double |
getDistanceForLevel(int level)
Given a cell having the specified level, returns the distance from opposite
corners.
|
int |
getLevelForDistance(double dist)
Returns the level of the largest grid in which its longest side is less
than or equal to the provided distance (in degrees).
|
int |
getNumSubCells(NumberRangePrefixTree.UnitNRShape lv)
Returns the number of sub-cells beneath the given UnitNRShape.
|
Cell |
getWorldCell()
Returns the level 0 cell which encompasses all spatial data.
|
protected NumberRangePrefixTree.NRCell[] |
newCellStack(int levels) |
NumberRangePrefixTree.NRShape |
parseShape(String str)
Detects a range pattern and parses it, otherwise it's parsed as one shape via
parseUnitShape(String) . |
protected abstract NumberRangePrefixTree.UnitNRShape |
parseUnitShape(String str)
Parse a String to a UnitNRShape.
|
Cell |
readCell(BytesRef term,
Cell scratch)
This creates a new Cell (or re-using
scratch if provided), initialized to the state as read
by the bytes. |
abstract Object |
toObject(NumberRangePrefixTree.UnitNRShape shape)
Converts a UnitNRShape shape to the corresponding type supported by this class, such as a Calendar/BigDecimal.
|
NumberRangePrefixTree.NRShape |
toRangeShape(NumberRangePrefixTree.UnitNRShape startUnit,
NumberRangePrefixTree.UnitNRShape endUnit)
Returns a shape that represents the continuous range between
start and end . |
protected NumberRangePrefixTree.UnitNRShape |
toShape(int[] valStack,
int len) |
String |
toString() |
protected abstract String |
toString(NumberRangePrefixTree.UnitNRShape lv)
A string representation of the UnitNRShape that is parse-able by
parseUnitShape(String) . |
protected static String |
toStringUnitRaw(NumberRangePrefixTree.UnitNRShape lv) |
abstract NumberRangePrefixTree.UnitNRShape |
toUnitShape(Object value)
Converts the value to a unit shape.
|
getMaxLevels, getSpatialContext, getTreeCellIterator
protected final int[] maxSubCellsByLevel
protected final int[] termLenByLevel
protected final int[] levelByTermLen
protected final int maxTermLen
public abstract NumberRangePrefixTree.UnitNRShape toUnitShape(Object value)
parseShape(String)
for
that. This is the reverse of toObject(org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.UnitNRShape)
.public NumberRangePrefixTree.NRShape toRangeShape(NumberRangePrefixTree.UnitNRShape startUnit, NumberRangePrefixTree.UnitNRShape endUnit)
start
and end
. It will
be normalized, and so sometimes a NumberRangePrefixTree.UnitNRShape
will be returned, other times a
NumberRangePrefixTree.SpanUnitsNRShape
will be.IllegalArgumentException
- if the arguments are in the wrong order, or if either contains the other (yet they
aren't equal).public abstract Object toObject(NumberRangePrefixTree.UnitNRShape shape)
toUnitShape(Object)
.protected abstract String toString(NumberRangePrefixTree.UnitNRShape lv)
parseUnitShape(String)
.protected static String toStringUnitRaw(NumberRangePrefixTree.UnitNRShape lv)
public NumberRangePrefixTree.NRShape parseShape(String str) throws ParseException
parseUnitShape(String)
. The range pattern looks like this BNF:
'[' + parseShapeLV + ' TO ' + parseShapeLV + ']'It's the same thing as the toString() of the range shape, notwithstanding range optimization.
str
- not null or emptyParseException
- If there is a problemprotected abstract NumberRangePrefixTree.UnitNRShape parseUnitShape(String str) throws ParseException
ParseException
protected static int comparePrefix(NumberRangePrefixTree.UnitNRShape a, NumberRangePrefixTree.UnitNRShape b)
public String toString()
toString
in class SpatialPrefixTree
public int getLevelForDistance(double dist)
SpatialPrefixTree
dist
acts as an error epsilon declaring the amount of detail needed in the
grid, such that you can get a grid with just the right amount of
precision.getLevelForDistance
in class SpatialPrefixTree
dist
- >= 0
public double getDistanceForLevel(int level)
SpatialPrefixTree
getDistanceForLevel
in class SpatialPrefixTree
level
- [1 to maxLevels]> 0
protected NumberRangePrefixTree.UnitNRShape toShape(int[] valStack, int len)
public Cell getWorldCell()
SpatialPrefixTree
SpatialPrefixTree.readCell(BytesRef,Cell)
with no bytes.getWorldCell
in class SpatialPrefixTree
protected NumberRangePrefixTree.NRCell[] newCellStack(int levels)
public Cell readCell(BytesRef term, Cell scratch)
SpatialPrefixTree
scratch
if provided), initialized to the state as read
by the bytes.
Warning: An implementation may refer to the same byte array (no copy). If Cell.setLeaf()
is
subsequently called, it would then modify these bytes.readCell
in class SpatialPrefixTree
public int getNumSubCells(NumberRangePrefixTree.UnitNRShape lv)
Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.