You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2010/09/27 06:07:25 UTC
svn commit: r1001582 - in /lucene/dev/trunk/lucene: CHANGES.txt
src/java/org/apache/lucene/search/FilteredTermsEnum.java
src/java/org/apache/lucene/search/NumericRangeQuery.java
Author: uschindler
Date: Mon Sep 27 04:07:25 2010
New Revision: 1001582
URL: http://svn.apache.org/viewvc?rev=1001582&view=rev
Log:
LUCENE-2669: Fix NumericRangeQuery.NumericRangeTermsEnum sometimes seeks backwards. This also adds an assert to FilteredTermsEnum that seeking only goes forward.
Modified:
lucene/dev/trunk/lucene/CHANGES.txt
lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/FilteredTermsEnum.java
lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/NumericRangeQuery.java
Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1001582&r1=1001581&r2=1001582&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Mon Sep 27 04:07:25 2010
@@ -253,6 +253,11 @@ Optimizations
interval from 128 to 32, because the terms index now requires much
less RAM. (Robert Muir, Mike McCandless)
+* LUCENE-2669: Optimize NumericRangeQuery.NumericRangeTermsEnum to
+ not seek backwards when a sub-range has no terms. It now only seeks
+ when the current term is less than the next sub-range's lower end.
+ (Uwe Schindler, Mike McCandless)
+
Documentation
* LUCENE-2579: Fix oal.search's package.html description of abstract
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/FilteredTermsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/FilteredTermsEnum.java?rev=1001582&r1=1001581&r2=1001582&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/FilteredTermsEnum.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/FilteredTermsEnum.java Mon Sep 27 04:07:25 2010
@@ -198,6 +198,8 @@ public abstract class FilteredTermsEnum
if (doSeek) {
doSeek = false;
final BytesRef t = nextSeekTerm(actualTerm);
+ // Make sure we always seek forward:
+ assert actualTerm == null || t == null || getComparator().compare(t, actualTerm) > 0: "curTerm=" + actualTerm + " seekTerm=" + t;
if (t == null || tenum.seek(t, useTermsCache) == SeekStatus.END) {
// no more terms to seek to or enum exhausted
return null;
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/NumericRangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/NumericRangeQuery.java?rev=1001582&r1=1001581&r2=1001582&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/NumericRangeQuery.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/NumericRangeQuery.java Mon Sep 27 04:07:25 2010
@@ -465,28 +465,47 @@ public final class NumericRangeQuery<T e
termComp = getComparator();
}
+ private void nextRange() {
+ assert rangeBounds.size() % 2 == 0;
+
+ currentLowerBound = rangeBounds.removeFirst();
+ assert currentUpperBound == null || termComp.compare(currentUpperBound, currentLowerBound) <= 0 :
+ "The current upper bound must be <= the new lower bound";
+
+ currentUpperBound = rangeBounds.removeFirst();
+ }
+
@Override
protected final BytesRef nextSeekTerm(BytesRef term) throws IOException {
- if (rangeBounds.size() >= 2) {
- assert rangeBounds.size() % 2 == 0;
-
- this.currentLowerBound = rangeBounds.removeFirst();
- assert currentUpperBound == null || termComp.compare(currentUpperBound, currentLowerBound) <= 0 :
- "The current upper bound must be <= the new lower bound";
+ while (rangeBounds.size() >= 2) {
+ nextRange();
- this.currentUpperBound = rangeBounds.removeFirst();
- return currentLowerBound;
+ // if the new upper bound is before the term parameter, the sub-range is never a hit
+ if (term != null && termComp.compare(term, currentUpperBound) > 0)
+ continue;
+ // never seek backwards, so use current term if lower bound is smaller
+ return (term != null && termComp.compare(term, currentLowerBound) > 0) ?
+ term : currentLowerBound;
}
// no more sub-range enums available
- assert rangeBounds.size() == 0;
+ assert rangeBounds.isEmpty();
+ currentLowerBound = currentUpperBound = null;
return null;
}
@Override
- protected AcceptStatus accept(BytesRef term) {
- return (currentUpperBound != null && termComp.compare(term, currentUpperBound) <= 0) ?
- AcceptStatus.YES : AcceptStatus.NO_AND_SEEK;
+ protected final AcceptStatus accept(BytesRef term) {
+ while (currentUpperBound == null || termComp.compare(term, currentUpperBound) > 0) {
+ if (rangeBounds.isEmpty())
+ return AcceptStatus.END;
+ // peek next sub-range, only seek if the current term is smaller than next lower bound
+ if (termComp.compare(term, rangeBounds.getFirst()) < 0)
+ return AcceptStatus.NO_AND_SEEK;
+ // step forward to next range without seeking, as next lower range bound is less or equal current term
+ nextRange();
+ }
+ return AcceptStatus.YES;
}
}