Class Intervals
- java.lang.Object
-
- org.apache.lucene.search.intervals.Intervals
-
public final class Intervals extends Object
Constructor functions forIntervalsSource
types These sources implement minimum-interval algorithms taken from the paper Efficient Optimally Lazy Algorithms for Minimal-Interval Semantics By default, sources that are sensitive to internal gaps (e.g. PHRASE and MAXGAPS) will rewrite their sub-sources so that disjunctions of different lengths are pulled up to the top of the interval tree. For example, PHRASE(or(PHRASE("a", "b", "c"), "b"), "c") will automatically rewrite itself to OR(PHRASE("a", "b", "c", "c"), PHRASE("b", "c")) to ensure that documents containing "b c" are matched. This can lead to less efficient queries, as more terms need to be loaded (for example, the "c" iterator above is loaded twice), so if you care more about speed than about accuracy you can use theor(boolean, IntervalsSource...)
factory method to prevent rewriting.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static IntervalsSource
after(IntervalsSource source, IntervalsSource reference)
Returns intervals from the source that appear after intervals from the referencestatic IntervalsSource
atLeast(int minShouldMatch, IntervalsSource... sources)
Return intervals that span combinations of intervals fromminShouldMatch
of the sourcesstatic IntervalsSource
before(IntervalsSource source, IntervalsSource reference)
Returns intervals from the source that appear before intervals from the referencestatic IntervalsSource
containedBy(IntervalsSource small, IntervalsSource big)
Create a contained-byIntervalsSource
Returns intervals from the small query that appear within intervals of the big querystatic IntervalsSource
containing(IntervalsSource big, IntervalsSource small)
Create a containingIntervalsSource
Returns intervals from the big source that contain one or more intervals from the small sourcestatic IntervalsSource
extend(IntervalsSource source, int before, int after)
Create anIntervalsSource
that wraps another source, extending its intervals by a number of positions before and after.static IntervalsSource
fixField(String field, IntervalsSource source)
Create anIntervalsSource
that always returns intervals from a specific field This is useful for comparing intervals across multiple fields, for example fields that have been analyzed differently, allowing you to search for stemmed terms near unstemmed terms, etc.static IntervalsSource
maxgaps(int gaps, IntervalsSource subSource)
Create anIntervalsSource
that filters a sub-source by its gapsstatic IntervalsSource
maxwidth(int width, IntervalsSource subSource)
Create anIntervalsSource
that filters a sub-source by the width of its intervalsstatic IntervalsSource
nonOverlapping(IntervalsSource minuend, IntervalsSource subtrahend)
Create a non-overlapping IntervalsSource Returns intervals of the minuend that do not overlap with intervals from the subtrahendstatic IntervalsSource
notContainedBy(IntervalsSource small, IntervalsSource big)
Create a not-contained-byIntervalsSource
Returns intervals from the smallIntervalsSource
that do not appear within intervals from the bigIntervalsSource
.static IntervalsSource
notContaining(IntervalsSource minuend, IntervalsSource subtrahend)
Create a not-containingIntervalsSource
Returns intervals from the minuend that do not contain intervals of the subtrahendstatic IntervalsSource
notWithin(IntervalsSource minuend, int positions, IntervalsSource subtrahend)
Create a not-withinIntervalsSource
Returns intervals of the minuend that do not appear within a set number of positions of intervals from the subtrahend querystatic IntervalsSource
or(boolean rewrite, List<IntervalsSource> subSources)
Return anIntervalsSource
over the disjunction of a set of sub-sourcesstatic IntervalsSource
or(boolean rewrite, IntervalsSource... subSources)
Return anIntervalsSource
over the disjunction of a set of sub-sourcesstatic IntervalsSource
or(List<IntervalsSource> subSources)
Return anIntervalsSource
over the disjunction of a set of sub-sourcesstatic IntervalsSource
or(IntervalsSource... subSources)
Return anIntervalsSource
over the disjunction of a set of sub-sources Automatically rewrites if wrapped by an interval source that is sensitive to internal gapsstatic IntervalsSource
ordered(IntervalsSource... subSources)
Create an orderedIntervalsSource
Returns intervals in which the subsources all appear in the given orderstatic IntervalsSource
overlapping(IntervalsSource source, IntervalsSource reference)
Returns intervals from a source that overlap with intervals from another sourcestatic IntervalsSource
phrase(String... terms)
Return anIntervalsSource
exposing intervals for a phrase consisting of a list of termsstatic IntervalsSource
phrase(IntervalsSource... subSources)
Return anIntervalsSource
exposing intervals for a phrase consisting of a list of IntervalsSourcesstatic IntervalsSource
prefix(String prefix)
Return anIntervalsSource
over the disjunction of all terms that begin with a prefixstatic IntervalsSource
term(String term)
Return anIntervalsSource
exposing intervals for a termstatic IntervalsSource
term(String term, Predicate<BytesRef> payloadFilter)
Return anIntervalsSource
exposing intervals for a term, filtered by the value of the term's payload at each positionstatic IntervalsSource
term(BytesRef term)
Return anIntervalsSource
exposing intervals for a termstatic IntervalsSource
term(BytesRef term, Predicate<BytesRef> payloadFilter)
Return anIntervalsSource
exposing intervals for a term, filtered by the value of the term's payload at each positionstatic IntervalsSource
unordered(boolean allowOverlaps, IntervalsSource... subSources)
Create an unorderedIntervalsSource
Returns intervals in which all the subsources appear.static IntervalsSource
unordered(IntervalsSource... subSources)
Create an unorderedIntervalsSource
Returns intervals in which all the subsources appear.static IntervalsSource
wildcard(String wildcard)
Return anIntervalsSource
over the disjunction of all terms that match a wildcard globstatic IntervalsSource
within(IntervalsSource source, int positions, IntervalsSource reference)
Returns intervals of the source that appear within a set number of positions of intervals from the reference
-
-
-
Method Detail
-
term
public static IntervalsSource term(BytesRef term)
Return anIntervalsSource
exposing intervals for a term
-
term
public static IntervalsSource term(String term)
Return anIntervalsSource
exposing intervals for a term
-
term
public static IntervalsSource term(String term, Predicate<BytesRef> payloadFilter)
Return anIntervalsSource
exposing intervals for a term, filtered by the value of the term's payload at each position
-
term
public static IntervalsSource term(BytesRef term, Predicate<BytesRef> payloadFilter)
Return anIntervalsSource
exposing intervals for a term, filtered by the value of the term's payload at each position
-
phrase
public static IntervalsSource phrase(String... terms)
Return anIntervalsSource
exposing intervals for a phrase consisting of a list of terms
-
phrase
public static IntervalsSource phrase(IntervalsSource... subSources)
Return anIntervalsSource
exposing intervals for a phrase consisting of a list of IntervalsSources
-
or
public static IntervalsSource or(IntervalsSource... subSources)
Return anIntervalsSource
over the disjunction of a set of sub-sources Automatically rewrites if wrapped by an interval source that is sensitive to internal gaps
-
or
public static IntervalsSource or(boolean rewrite, IntervalsSource... subSources)
Return anIntervalsSource
over the disjunction of a set of sub-sources- Parameters:
rewrite
- iffalse
, do not rewrite intervals that are sensitive to internal gaps; this may run more efficiently, but can miss valid hits due to minimizationsubSources
- the sources to combine
-
or
public static IntervalsSource or(List<IntervalsSource> subSources)
Return anIntervalsSource
over the disjunction of a set of sub-sources
-
or
public static IntervalsSource or(boolean rewrite, List<IntervalsSource> subSources)
Return anIntervalsSource
over the disjunction of a set of sub-sources- Parameters:
rewrite
- iffalse
, do not rewrite intervals that are sensitive to internal gaps; this may run more efficiently, but can miss valid hits due to minimizationsubSources
- the sources to combine
-
prefix
public static IntervalsSource prefix(String prefix)
Return anIntervalsSource
over the disjunction of all terms that begin with a prefix- Throws:
IllegalStateException
- if the prefix expands to more than 128 terms
-
wildcard
public static IntervalsSource wildcard(String wildcard)
Return anIntervalsSource
over the disjunction of all terms that match a wildcard glob- Throws:
IllegalStateException
- if the wildcard glob expands to more than 128 terms- See Also:
for glob format
-
maxwidth
public static IntervalsSource maxwidth(int width, IntervalsSource subSource)
Create anIntervalsSource
that filters a sub-source by the width of its intervals- Parameters:
width
- the maximum width of intervals in the sub-source to filtersubSource
- the sub-source to filter
-
maxgaps
public static IntervalsSource maxgaps(int gaps, IntervalsSource subSource)
Create anIntervalsSource
that filters a sub-source by its gaps- Parameters:
gaps
- the maximum number of gaps in the sub-source to filtersubSource
- the sub-source to filter
-
extend
public static IntervalsSource extend(IntervalsSource source, int before, int after)
Create anIntervalsSource
that wraps another source, extending its intervals by a number of positions before and after. This can be useful for adding defined gaps in a block query; for example, to find 'a b [2 arbitrary terms] c', you can call:Intervals.phrase(Intervals.term("a"), Intervals.extend(Intervals.term("b"), 0, 2), Intervals.term("c"));
Note that callingIntervalIterator.gaps()
on iterators returned by this source delegates directly to the wrapped iterator, and does not include the extensions.- Parameters:
source
- the source to extendbefore
- how many positions to extend before the delegated intervalafter
- how many positions to extend after the delegated interval
-
ordered
public static IntervalsSource ordered(IntervalsSource... subSources)
Create an orderedIntervalsSource
Returns intervals in which the subsources all appear in the given order- Parameters:
subSources
- an ordered set ofIntervalsSource
objects
-
unordered
public static IntervalsSource unordered(IntervalsSource... subSources)
Create an unorderedIntervalsSource
Returns intervals in which all the subsources appear. The subsources may overlap- Parameters:
subSources
- an unordered set ofIntervalsSource
s
-
unordered
public static IntervalsSource unordered(boolean allowOverlaps, IntervalsSource... subSources)
Create an unorderedIntervalsSource
Returns intervals in which all the subsources appear.- Parameters:
subSources
- an unordered set ofIntervalsSource
sallowOverlaps
- whether or not the sources should be allowed to overlap in a hit
-
fixField
public static IntervalsSource fixField(String field, IntervalsSource source)
Create anIntervalsSource
that always returns intervals from a specific field This is useful for comparing intervals across multiple fields, for example fields that have been analyzed differently, allowing you to search for stemmed terms near unstemmed terms, etc.
-
nonOverlapping
public static IntervalsSource nonOverlapping(IntervalsSource minuend, IntervalsSource subtrahend)
Create a non-overlapping IntervalsSource Returns intervals of the minuend that do not overlap with intervals from the subtrahend- Parameters:
minuend
- theIntervalsSource
to filtersubtrahend
- theIntervalsSource
to filter by
-
overlapping
public static IntervalsSource overlapping(IntervalsSource source, IntervalsSource reference)
Returns intervals from a source that overlap with intervals from another source- Parameters:
source
- the source to filterreference
- the source to filter by
-
notWithin
public static IntervalsSource notWithin(IntervalsSource minuend, int positions, IntervalsSource subtrahend)
Create a not-withinIntervalsSource
Returns intervals of the minuend that do not appear within a set number of positions of intervals from the subtrahend query- Parameters:
minuend
- theIntervalsSource
to filterpositions
- the minimum distance that intervals from the minuend may occur from intervals of the subtrahendsubtrahend
- theIntervalsSource
to filter by
-
within
public static IntervalsSource within(IntervalsSource source, int positions, IntervalsSource reference)
Returns intervals of the source that appear within a set number of positions of intervals from the reference- Parameters:
source
- theIntervalsSource
to filterpositions
- the maximum distance that intervals of the source may occur from intervals of the referencereference
- theIntervalsSource
to filter by
-
notContaining
public static IntervalsSource notContaining(IntervalsSource minuend, IntervalsSource subtrahend)
Create a not-containingIntervalsSource
Returns intervals from the minuend that do not contain intervals of the subtrahend- Parameters:
minuend
- theIntervalsSource
to filtersubtrahend
- theIntervalsSource
to filter by
-
containing
public static IntervalsSource containing(IntervalsSource big, IntervalsSource small)
Create a containingIntervalsSource
Returns intervals from the big source that contain one or more intervals from the small source- Parameters:
big
- theIntervalsSource
to filtersmall
- theIntervalsSource
to filter by
-
notContainedBy
public static IntervalsSource notContainedBy(IntervalsSource small, IntervalsSource big)
Create a not-contained-byIntervalsSource
Returns intervals from the smallIntervalsSource
that do not appear within intervals from the bigIntervalsSource
.- Parameters:
small
- theIntervalsSource
to filterbig
- theIntervalsSource
to filter by
-
containedBy
public static IntervalsSource containedBy(IntervalsSource small, IntervalsSource big)
Create a contained-byIntervalsSource
Returns intervals from the small query that appear within intervals of the big query- Parameters:
small
- theIntervalsSource
to filterbig
- theIntervalsSource
to filter by
-
atLeast
public static IntervalsSource atLeast(int minShouldMatch, IntervalsSource... sources)
Return intervals that span combinations of intervals fromminShouldMatch
of the sources
-
before
public static IntervalsSource before(IntervalsSource source, IntervalsSource reference)
Returns intervals from the source that appear before intervals from the reference
-
after
public static IntervalsSource after(IntervalsSource source, IntervalsSource reference)
Returns intervals from the source that appear after intervals from the reference
-
-