LUCENE-5691: DocTermOrds lookupTerm is wrong in some cases

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1596370 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-05-20 19:18:28 +00:00
parent 86e7b08381
commit a67d9a89a0
3 changed files with 23 additions and 4 deletions

View File

@ -196,6 +196,10 @@ Bug fixes
* LUCENE-5682: NPE in QueryRescorer when Scorer is null * LUCENE-5682: NPE in QueryRescorer when Scorer is null
(Joel Bernstein, Mike McCandless) (Joel Bernstein, Mike McCandless)
* LUCENE-5691: DocTermOrds lookupTerm(BytesRef) would return incorrect results
if the underlying TermsEnum supports ord() and the insertion point would
be at the end. (Robert Muir)
Test Framework Test Framework
* LUCENE-5622: Fail tests if they print over the given limit of bytes to * LUCENE-5622: Fail tests if they print over the given limit of bytes to

View File

@ -894,10 +894,15 @@ public class DocTermOrds {
@Override @Override
public long lookupTerm(BytesRef key) { public long lookupTerm(BytesRef key) {
try { try {
if (te.seekCeil(key) == SeekStatus.FOUND) { switch (te.seekCeil(key)) {
case FOUND:
assert te.ord() >= 0;
return te.ord(); return te.ord();
} else { case NOT_FOUND:
assert te.ord() >= 0;
return -te.ord()-1; return -te.ord()-1;
default: /* END */
return -numTerms()-1;
} }
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);

View File

@ -579,6 +579,16 @@ public class TestDocTermOrds extends LuceneTestCase {
termsEnum.seekExact(2); termsEnum.seekExact(2);
assertEquals("world", termsEnum.term().utf8ToString()); assertEquals("world", termsEnum.term().utf8ToString());
assertEquals(2, termsEnum.ord()); assertEquals(2, termsEnum.ord());
// lookupTerm(BytesRef)
assertEquals(-1, dv.lookupTerm(new BytesRef("apple")));
assertEquals(0, dv.lookupTerm(new BytesRef("beer")));
assertEquals(-2, dv.lookupTerm(new BytesRef("car")));
assertEquals(1, dv.lookupTerm(new BytesRef("hello")));
assertEquals(-3, dv.lookupTerm(new BytesRef("matter")));
assertEquals(2, dv.lookupTerm(new BytesRef("world")));
assertEquals(-4, dv.lookupTerm(new BytesRef("zany")));
ireader.close(); ireader.close();
directory.close(); directory.close();
} }