From ec788948a64955acc0415281f353d4d7b2f797cc Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Mon, 21 Jul 2014 09:41:40 +0000 Subject: [PATCH] LUCENE-5819: fix ord bug; add test case; remove dead code git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1612217 13f79535-47bb-0310-9956-ffa450edef68 --- dev-tools/scripts/diffSources.py | 2 +- .../blocktreeords/OrdsSegmentTermsEnum.java | 1 + .../OrdsSegmentTermsEnumFrame.java | 19 +++---------- .../blocktreeords/TestOrdsBlockTree.java | 27 +++++++++++++++++++ .../blocktree/SegmentTermsEnumFrame.java | 13 --------- 5 files changed, 33 insertions(+), 29 deletions(-) diff --git a/dev-tools/scripts/diffSources.py b/dev-tools/scripts/diffSources.py index 92bd4b9f74b..8e702821ade 100644 --- a/dev-tools/scripts/diffSources.py +++ b/dev-tools/scripts/diffSources.py @@ -60,7 +60,7 @@ while True: keep = True else: ext = os.path.splitext(l)[-1] - keep = ext in ('.xml', '.iml', '.html', '.template', '.py', '.g', '.properties') + keep = ext in ('.xml', '.iml', '.html', '.template', '.py', '.g', '.properties', '.java') if keep: print diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsSegmentTermsEnum.java b/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsSegmentTermsEnum.java index e33c13c301e..e3b19356055 100644 --- a/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsSegmentTermsEnum.java +++ b/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsSegmentTermsEnum.java @@ -186,6 +186,7 @@ public final class OrdsSegmentTermsEnum extends TermsEnum { // } } assert length == f.prefix; + assert termOrd == f.termOrdOrig; } else { f.nextEnt = -1; f.prefix = length; diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsSegmentTermsEnumFrame.java b/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsSegmentTermsEnumFrame.java index 83edf657abd..17911425e88 100644 --- a/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsSegmentTermsEnumFrame.java +++ b/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsSegmentTermsEnumFrame.java @@ -655,19 +655,6 @@ final class OrdsSegmentTermsEnumFrame { // return NOT_FOUND: fillTerm(); - if (!exactOnly && !ste.termExists) { - // We are on a sub-block, and caller wants - // us to position to the next term after - // the target, so we must recurse into the - // sub-frame(s): - ste.currentFrame = ste.pushFrame(null, ste.currentFrame.lastSubFP, termLen, ste.currentFrame.termOrd); - ste.currentFrame.loadBlock(); - while (ste.currentFrame.next()) { - ste.currentFrame = ste.pushFrame(null, ste.currentFrame.lastSubFP, ste.term.length, ste.currentFrame.termOrd); - ste.currentFrame.loadBlock(); - } - } - //if (DEBUG) System.out.println(" not found"); return SeekStatus.NOT_FOUND; } else if (stop) { @@ -742,6 +729,8 @@ final class OrdsSegmentTermsEnumFrame { final int termLen = prefix + suffix; startBytePos = suffixesReader.getPosition(); suffixesReader.skipBytes(suffix); + // Must save ord before we skip over a sub-block in case we push, below: + long prevTermOrd = termOrd; if (ste.termExists) { state.termBlockOrd++; termOrd++; @@ -795,10 +784,10 @@ final class OrdsSegmentTermsEnumFrame { // us to position to the next term after // the target, so we must recurse into the // sub-frame(s): - ste.currentFrame = ste.pushFrame(null, ste.currentFrame.lastSubFP, termLen, ste.currentFrame.termOrd); + ste.currentFrame = ste.pushFrame(null, ste.currentFrame.lastSubFP, termLen, prevTermOrd); ste.currentFrame.loadBlock(); while (ste.currentFrame.next()) { - ste.currentFrame = ste.pushFrame(null, ste.currentFrame.lastSubFP, ste.term.length, ste.currentFrame.termOrd); + ste.currentFrame = ste.pushFrame(null, ste.currentFrame.lastSubFP, ste.term.length, prevTermOrd); ste.currentFrame.loadBlock(); } } diff --git a/lucene/codecs/src/test/org/apache/lucene/codecs/blocktreeords/TestOrdsBlockTree.java b/lucene/codecs/src/test/org/apache/lucene/codecs/blocktreeords/TestOrdsBlockTree.java index 166fb0587e7..3a1fbe3e4d0 100644 --- a/lucene/codecs/src/test/org/apache/lucene/codecs/blocktreeords/TestOrdsBlockTree.java +++ b/lucene/codecs/src/test/org/apache/lucene/codecs/blocktreeords/TestOrdsBlockTree.java @@ -357,4 +357,31 @@ public class TestOrdsBlockTree extends BasePostingsFormatTestCase { w.close(); dir.close(); } + + public void testSeekCeilNotFound() throws Exception { + Directory dir = newDirectory(); + RandomIndexWriter w = new RandomIndexWriter(random(), dir); + Document doc = new Document(); + // Get empty string in there! + doc.add(newStringField("field", "", Field.Store.NO)); + w.addDocument(doc); + + for(int i=0;i<36;i++) { + doc = new Document(); + String term = "" + (char) (97+i); + String term2 = "a" + (char) (97+i); + doc.add(newTextField("field", term + " " + term2, Field.Store.NO)); + w.addDocument(doc); + } + + w.forceMerge(1); + IndexReader r = w.getReader(); + TermsEnum te = MultiFields.getTerms(r, "field").iterator(null); + assertEquals(TermsEnum.SeekStatus.NOT_FOUND, te.seekCeil(new BytesRef(new byte[] {0x22}))); + assertEquals("a", te.term().utf8ToString()); + assertEquals(1L, te.ord()); + r.close(); + w.close(); + dir.close(); + } } diff --git a/lucene/core/src/java/org/apache/lucene/codecs/blocktree/SegmentTermsEnumFrame.java b/lucene/core/src/java/org/apache/lucene/codecs/blocktree/SegmentTermsEnumFrame.java index ec681d92473..98e5d41f8b0 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/blocktree/SegmentTermsEnumFrame.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/blocktree/SegmentTermsEnumFrame.java @@ -552,19 +552,6 @@ final class SegmentTermsEnumFrame { // return NOT_FOUND: fillTerm(); - if (!exactOnly && !ste.termExists) { - // We are on a sub-block, and caller wants - // us to position to the next term after - // the target, so we must recurse into the - // sub-frame(s): - ste.currentFrame = ste.pushFrame(null, ste.currentFrame.lastSubFP, termLen); - ste.currentFrame.loadBlock(); - while (ste.currentFrame.next()) { - ste.currentFrame = ste.pushFrame(null, ste.currentFrame.lastSubFP, ste.term.length); - ste.currentFrame.loadBlock(); - } - } - //if (DEBUG) System.out.println(" not found"); return SeekStatus.NOT_FOUND; } else if (stop) {