mirror of https://github.com/apache/lucene.git
LUCENE-2087: Remove recursion in NumericRangeTermEnum
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@882977 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
254e3e9293
commit
d838d7bf3a
|
@ -18,7 +18,10 @@ New features
|
||||||
Optimizations
|
Optimizations
|
||||||
|
|
||||||
* LUCENE-2086: When resolving deleted terms, do so in term sort order
|
* LUCENE-2086: When resolving deleted terms, do so in term sort order
|
||||||
for better performance (Bogdan Ghidireac via Mike McCandless)
|
for better performance. (Bogdan Ghidireac via Mike McCandless)
|
||||||
|
|
||||||
|
* LUCENE-2087: Remove recursion in NumericRangeTermEnum.
|
||||||
|
(Uwe Schindler)
|
||||||
|
|
||||||
Build
|
Build
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.lucene.util.ToStringUtils;
|
||||||
import org.apache.lucene.util.StringHelper;
|
import org.apache.lucene.util.StringHelper;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
import org.apache.lucene.index.TermEnum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>A {@link Query} that matches numeric values within a
|
* <p>A {@link Query} that matches numeric values within a
|
||||||
|
@ -486,6 +487,12 @@ public final class NumericRangeQuery<T extends Number> extends MultiTermQuery {
|
||||||
throw new UnsupportedOperationException("not implemented");
|
throw new UnsupportedOperationException("not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** this is a dummy, it is not used by this class. */
|
||||||
|
@Override
|
||||||
|
protected void setEnum(TermEnum tenum) {
|
||||||
|
throw new UnsupportedOperationException("not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares if current upper bound is reached,
|
* Compares if current upper bound is reached,
|
||||||
* this also updates the term count for statistics.
|
* this also updates the term count for statistics.
|
||||||
|
@ -507,29 +514,35 @@ public final class NumericRangeQuery<T extends Number> extends MultiTermQuery {
|
||||||
assert actualEnum != null;
|
assert actualEnum != null;
|
||||||
if (actualEnum.next()) {
|
if (actualEnum.next()) {
|
||||||
currentTerm = actualEnum.term();
|
currentTerm = actualEnum.term();
|
||||||
if (termCompare(currentTerm)) return true;
|
if (termCompare(currentTerm))
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if all above fails, we go forward to the next enum,
|
// if all above fails, we go forward to the next enum,
|
||||||
// if one is available
|
// if one is available
|
||||||
currentTerm = null;
|
currentTerm = null;
|
||||||
if (rangeBounds.size() < 2) {
|
while (rangeBounds.size() >= 2) {
|
||||||
assert rangeBounds.size() == 0;
|
assert rangeBounds.size() % 2 == 0;
|
||||||
return false;
|
// close the current enum and read next bounds
|
||||||
|
if (actualEnum != null) {
|
||||||
|
actualEnum.close();
|
||||||
|
actualEnum = null;
|
||||||
|
}
|
||||||
|
final String lowerBound = rangeBounds.removeFirst();
|
||||||
|
this.currentUpperBound = rangeBounds.removeFirst();
|
||||||
|
// create a new enum
|
||||||
|
actualEnum = reader.terms(termTemplate.createTerm(lowerBound));
|
||||||
|
currentTerm = actualEnum.term();
|
||||||
|
if (currentTerm != null && termCompare(currentTerm))
|
||||||
|
return true;
|
||||||
|
// clear the current term for next iteration
|
||||||
|
currentTerm = null;
|
||||||
}
|
}
|
||||||
// close the current enum and read next bounds
|
|
||||||
if (actualEnum != null) {
|
// no more sub-range enums available
|
||||||
actualEnum.close();
|
assert rangeBounds.size() == 0 && currentTerm == null;
|
||||||
actualEnum = null;
|
return false;
|
||||||
}
|
|
||||||
final String lowerBound = rangeBounds.removeFirst();
|
|
||||||
this.currentUpperBound = rangeBounds.removeFirst();
|
|
||||||
// this call recursively uses next(), if no valid term in
|
|
||||||
// next enum found.
|
|
||||||
// if this behavior is changed/modified in the superclass,
|
|
||||||
// this enum will not work anymore!
|
|
||||||
setEnum(reader.terms(termTemplate.createTerm(lowerBound)));
|
|
||||||
return (currentTerm != null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Closes the enumeration to further activity, freeing resources. */
|
/** Closes the enumeration to further activity, freeing resources. */
|
||||||
|
|
Loading…
Reference in New Issue