public final class NodeNumericRangeQuery<T extends Number> extends MultiNodeTermQuery
NodePrimitiveQuery
that matches numeric values within a
specified range.
To use this, you must first index the
numeric values using NumericField
(expert: NumericTokenStream
). If your terms are instead textual,
you should use NodeTermRangeQuery
.
You create a new NodeNumericRangeQuery
with the static
factory methods, eg:
Query q = NodeNumericRangeQuery.newFloatRange("weight", 0.03f, 0.10f, true, true);matches all documents whose float valued "weight" field ranges from 0.03 to 0.10, inclusive.
The performance of NodeNumericRangeQuery
is much better
than the corresponding NodeTermRangeQuery
because the
number of terms that must be searched is usually far
fewer, thanks to trie indexing, described below.
You can optionally specify a precisionStep
when creating this query. This is necessary if you've
changed this configuration from its default (4) during
indexing. Lower values consume more disk space but speed
up searching. Suitable values are between 1 and
8. A good starting point to test is 4,
which is the default value for all Numeric*
classes. See below for
details.
This query defaults to MultiNodeTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT and never relies on uses MultiNodeTermQuery.CONSTANT_SCORE_FILTER_REWRITE. Good performance is expected for 32 bit (int/float) ranges with precisionStep ≤8 and 64 bit (long/double) ranges with precisionStep ≤6. In the other cases, bad performance has to be expected as the number of terms is likely to be high.
See NumericRangeQuery
for more information on how it works.
Code taken from NumericRangeQuery
and adapted for SIREn.
MultiNodeTermQuery.RewriteMethod
CONSTANT_SCORE_AUTO_REWRITE_DEFAULT, CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE, CONSTANT_SCORE_FILTER_REWRITE, field, rewriteMethod, SCORING_BOOLEAN_QUERY_REWRITE
ancestor, levelConstraint, lowerBound, upperBound
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
T |
getMax()
Returns the upper value of this range query
|
T |
getMin()
Returns the lower value of this range query
|
int |
getPrecisionStep()
Returns the precision step.
|
protected org.apache.lucene.index.TermsEnum |
getTermsEnum(org.apache.lucene.index.Terms terms,
org.apache.lucene.util.AttributeSource atts)
Construct the enumeration to be used, expanding the
pattern term.
|
int |
hashCode() |
boolean |
includesMax()
Returns
true if the upper endpoint is inclusive |
boolean |
includesMin()
Returns
true if the lower endpoint is inclusive |
static NodeNumericRangeQuery<Double> |
newDoubleRange(String field,
Double min,
Double max,
boolean minInclusive,
boolean maxInclusive)
Factory that creates a
SirenNumericRangeQuery , that queries a double
range using the default precisionStep NumericUtils.PRECISION_STEP_DEFAULT (4). |
static NodeNumericRangeQuery<Double> |
newDoubleRange(String field,
int precisionStep,
Double min,
Double max,
boolean minInclusive,
boolean maxInclusive)
Factory that creates a
SirenNumericRangeQuery , that queries a double
range using the given precisionStep . |
static NodeNumericRangeQuery<Float> |
newFloatRange(String field,
Float min,
Float max,
boolean minInclusive,
boolean maxInclusive)
Factory that creates a
SirenNumericRangeQuery , that queries a float
range using the default precisionStep NumericUtils.PRECISION_STEP_DEFAULT (4). |
static NodeNumericRangeQuery<Float> |
newFloatRange(String field,
int precisionStep,
Float min,
Float max,
boolean minInclusive,
boolean maxInclusive)
Factory that creates a
SirenNumericRangeQuery , that queries a float
range using the given precisionStep . |
static NodeNumericRangeQuery<Integer> |
newIntRange(String field,
Integer min,
Integer max,
boolean minInclusive,
boolean maxInclusive)
Factory that creates a
SirenNumericRangeQuery , that queries a int
range using the default precisionStep NumericUtils.PRECISION_STEP_DEFAULT (4). |
static NodeNumericRangeQuery<Integer> |
newIntRange(String field,
int precisionStep,
Integer min,
Integer max,
boolean minInclusive,
boolean maxInclusive)
Factory that creates a
SirenNumericRangeQuery , that queries a int
range using the given precisionStep . |
static NodeNumericRangeQuery<Long> |
newLongRange(String field,
int precisionStep,
Long min,
Long max,
boolean minInclusive,
boolean maxInclusive)
Factory that creates a
SirenNumericRangeQuery , that queries a long
range using the given precisionStep . |
static NodeNumericRangeQuery<Long> |
newLongRange(String field,
Long min,
Long max,
boolean minInclusive,
boolean maxInclusive)
Factory that creates a
SirenNumericRangeQuery , that queries a long
range using the default precisionStep NumericUtils.PRECISION_STEP_DEFAULT (4). |
String |
toString(String field) |
getField, getRewriteMethod, getTermsEnum, rewrite, setRewriteMethod
setDatatype, wrapToStringWithDatatype
getDocsNodesAndPositionsEnum, getLevelConstraint, getNodeConstraint, setAncestorPointer, setLevelConstraint, setNodeConstraint, setNodeConstraint
public static NodeNumericRangeQuery<Long> newLongRange(String field, int precisionStep, Long min, Long max, boolean minInclusive, boolean maxInclusive)
SirenNumericRangeQuery
, that queries a long
range using the given precisionStep
.
You can have half-open ranges (which are in fact </≤ or >/≥ queries)
by setting the min or max value to null
. By setting inclusive to false, it will
match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.public static NodeNumericRangeQuery<Long> newLongRange(String field, Long min, Long max, boolean minInclusive, boolean maxInclusive)
SirenNumericRangeQuery
, that queries a long
range using the default precisionStep
NumericUtils.PRECISION_STEP_DEFAULT
(4).
You can have half-open ranges (which are in fact </≤ or >/≥ queries)
by setting the min or max value to null
. By setting inclusive to false, it will
match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.public static NodeNumericRangeQuery<Integer> newIntRange(String field, int precisionStep, Integer min, Integer max, boolean minInclusive, boolean maxInclusive)
SirenNumericRangeQuery
, that queries a int
range using the given precisionStep
.
You can have half-open ranges (which are in fact </≤ or >/≥ queries)
by setting the min or max value to null
. By setting inclusive to false, it will
match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.public static NodeNumericRangeQuery<Integer> newIntRange(String field, Integer min, Integer max, boolean minInclusive, boolean maxInclusive)
SirenNumericRangeQuery
, that queries a int
range using the default precisionStep
NumericUtils.PRECISION_STEP_DEFAULT
(4).
You can have half-open ranges (which are in fact </≤ or >/≥ queries)
by setting the min or max value to null
. By setting inclusive to false, it will
match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.public static NodeNumericRangeQuery<Double> newDoubleRange(String field, int precisionStep, Double min, Double max, boolean minInclusive, boolean maxInclusive)
SirenNumericRangeQuery
, that queries a double
range using the given precisionStep
.
You can have half-open ranges (which are in fact </≤ or >/≥ queries)
by setting the min or max value to null
. By setting inclusive to false, it will
match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.public static NodeNumericRangeQuery<Double> newDoubleRange(String field, Double min, Double max, boolean minInclusive, boolean maxInclusive)
SirenNumericRangeQuery
, that queries a double
range using the default precisionStep
NumericUtils.PRECISION_STEP_DEFAULT
(4).
You can have half-open ranges (which are in fact </≤ or >/≥ queries)
by setting the min or max value to null
. By setting inclusive to false, it will
match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.public static NodeNumericRangeQuery<Float> newFloatRange(String field, int precisionStep, Float min, Float max, boolean minInclusive, boolean maxInclusive)
SirenNumericRangeQuery
, that queries a float
range using the given precisionStep
.
You can have half-open ranges (which are in fact </≤ or >/≥ queries)
by setting the min or max value to null
. By setting inclusive to false, it will
match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.public static NodeNumericRangeQuery<Float> newFloatRange(String field, Float min, Float max, boolean minInclusive, boolean maxInclusive)
SirenNumericRangeQuery
, that queries a float
range using the default precisionStep
NumericUtils.PRECISION_STEP_DEFAULT
(4).
You can have half-open ranges (which are in fact </≤ or >/≥ queries)
by setting the min or max value to null
. By setting inclusive to false, it will
match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.protected org.apache.lucene.index.TermsEnum getTermsEnum(org.apache.lucene.index.Terms terms, org.apache.lucene.util.AttributeSource atts) throws IOException
MultiNodeTermQuery
TermsEnum.EMPTY
if no
terms match). The TermsEnum must already be
positioned to the first matching term.
The given AttributeSource
is passed by the MultiNodeTermQuery.RewriteMethod
to
provide attributes, the rewrite method uses to inform about e.g. maximum competitive boosts.
This is currently only used by TopNodeTermsRewrite
getTermsEnum
in class MultiNodeTermQuery
IOException
public boolean includesMin()
true
if the lower endpoint is inclusivepublic boolean includesMax()
true
if the upper endpoint is inclusivepublic T getMin()
public T getMax()
public int getPrecisionStep()
public String toString(String field)
toString
in class org.apache.lucene.search.Query
public final boolean equals(Object o)
equals
in class MultiNodeTermQuery
public final int hashCode()
hashCode
in class MultiNodeTermQuery
Copyright © 2014. All rights reserved.