lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1596370 - in /lucene/dev/trunk/lucene: CHANGES.txt misc/src/java/org/apache/lucene/uninverting/DocTermOrds.java misc/src/test/org/apache/lucene/uninverting/TestDocTermOrds.java
Date Tue, 20 May 2014 19:18:28 GMT
Author: rmuir
Date: Tue May 20 19:18:28 2014
New Revision: 1596370

URL: http://svn.apache.org/r1596370
Log:
LUCENE-5691: DocTermOrds lookupTerm is wrong in some cases

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/uninverting/DocTermOrds.java
    lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/uninverting/TestDocTermOrds.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1596370&r1=1596369&r2=1596370&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Tue May 20 19:18:28 2014
@@ -196,6 +196,10 @@ Bug fixes
 * LUCENE-5682: NPE in QueryRescorer when Scorer is null
   (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
 
 * LUCENE-5622: Fail tests if they print over the given limit of bytes to 

Modified: lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/uninverting/DocTermOrds.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/uninverting/DocTermOrds.java?rev=1596370&r1=1596369&r2=1596370&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/uninverting/DocTermOrds.java (original)
+++ lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/uninverting/DocTermOrds.java Tue
May 20 19:18:28 2014
@@ -894,10 +894,15 @@ public class DocTermOrds {
     @Override
     public long lookupTerm(BytesRef key) {
       try {
-        if (te.seekCeil(key) == SeekStatus.FOUND) {
-          return te.ord();
-        } else {
-          return -te.ord()-1;
+        switch (te.seekCeil(key)) {
+          case FOUND:           
+            assert te.ord() >= 0;
+            return te.ord();
+          case NOT_FOUND:
+            assert te.ord() >= 0;
+            return -te.ord()-1;
+          default: /* END */
+            return -numTerms()-1;
         }
       } catch (IOException e) {
         throw new RuntimeException(e);

Modified: lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/uninverting/TestDocTermOrds.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/uninverting/TestDocTermOrds.java?rev=1596370&r1=1596369&r2=1596370&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/uninverting/TestDocTermOrds.java
(original)
+++ lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/uninverting/TestDocTermOrds.java
Tue May 20 19:18:28 2014
@@ -579,6 +579,16 @@ public class TestDocTermOrds extends Luc
     termsEnum.seekExact(2);
     assertEquals("world", termsEnum.term().utf8ToString());
     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();
     directory.close();
   }



Mime
View raw message