From 9285e08bceeb11cd38bdc0028e7b6168fc88dd3b Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Thu, 30 Jun 2011 16:05:42 +0000 Subject: [PATCH] LUCENE-3260: fix wrong result from MultiTermsEnum.next() after seekExact git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1141593 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/index/MultiTermsEnum.java | 15 ++ .../apache/lucene/index/TestTermsEnum.java | 143 ++++++++++++++++++ .../org/apache/lucene/util/fst/TestFSTs.java | 4 +- .../taxonomy/lucene/LuceneTaxonomyWriter.java | 12 +- 4 files changed, 161 insertions(+), 13 deletions(-) create mode 100644 lucene/src/test/org/apache/lucene/index/TestTermsEnum.java diff --git a/lucene/src/java/org/apache/lucene/index/MultiTermsEnum.java b/lucene/src/java/org/apache/lucene/index/MultiTermsEnum.java index 13579498d1a..330b76d061b 100644 --- a/lucene/src/java/org/apache/lucene/index/MultiTermsEnum.java +++ b/lucene/src/java/org/apache/lucene/index/MultiTermsEnum.java @@ -43,6 +43,7 @@ public final class MultiTermsEnum extends TermsEnum { private final MultiDocsAndPositionsEnum.EnumWithSlice[] subDocsAndPositions; private BytesRef lastSeek; + private boolean lastSeekExact; private final BytesRef lastSeekScratch = new BytesRef(); private int numTop; @@ -149,6 +150,7 @@ public final class MultiTermsEnum extends TermsEnum { } lastSeek = null; + lastSeekExact = true; for(int i=0;i terms = new ArrayList(); + final TermsEnum termsEnum = MultiFields.getTerms(r, "body").iterator(); + BytesRef term; + while((term = termsEnum.next()) != null) { + terms.add(new BytesRef(term)); + } + if (VERBOSE) { + System.out.println("TEST: " + terms.size() + " terms"); + } + + int upto = -1; + final int iters = atLeast(200); + for(int iter=0;iter= terms.size()) { + assertEquals(TermsEnum.SeekStatus.END, status); + upto = -1; + } else { + assertEquals(TermsEnum.SeekStatus.NOT_FOUND, status); + assertEquals(terms.get(upto), termsEnum.term()); + } + } else { + assertEquals(TermsEnum.SeekStatus.FOUND, status); + assertEquals(terms.get(upto), termsEnum.term()); + } + } else { + if (VERBOSE) { + System.out.println("TEST: iter seekExact target=" + target.utf8ToString() + " exists=" + exists); + } + // seekExact + final boolean result = termsEnum.seekExact(target, false); + if (VERBOSE) { + System.out.println(" got " + result); + } + if (upto < 0) { + assertFalse(result); + upto = -1; + } else { + assertTrue(result); + assertEquals(target, termsEnum.term()); + } + } + } + } + + r.close(); + d.close(); + } +} diff --git a/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java b/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java index f5e9c592fa4..bb9778bec3e 100644 --- a/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java +++ b/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java @@ -714,12 +714,12 @@ public class TestFSTs extends LuceneTestCase { if (random.nextBoolean()) { if (VERBOSE) { - System.out.println(" do advanceCeil(" + inputToString(inputMode, pairs.get(upto).input) + ")"); + System.out.println(" do seekCeil(" + inputToString(inputMode, pairs.get(upto).input) + ")"); } isDone = fstEnum.seekCeil(pairs.get(upto).input) == null; } else { if (VERBOSE) { - System.out.println(" do advanceFloor(" + inputToString(inputMode, pairs.get(upto).input) + ")"); + System.out.println(" do seekFloor(" + inputToString(inputMode, pairs.get(upto).input) + ")"); } isDone = fstEnum.seekFloor(pairs.get(upto).input) == null; } diff --git a/modules/facet/src/java/org/apache/lucene/facet/taxonomy/lucene/LuceneTaxonomyWriter.java b/modules/facet/src/java/org/apache/lucene/facet/taxonomy/lucene/LuceneTaxonomyWriter.java index efc27ffdc90..64ff572645c 100644 --- a/modules/facet/src/java/org/apache/lucene/facet/taxonomy/lucene/LuceneTaxonomyWriter.java +++ b/modules/facet/src/java/org/apache/lucene/facet/taxonomy/lucene/LuceneTaxonomyWriter.java @@ -27,10 +27,8 @@ import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.index.LogByteSizeMergePolicy; import org.apache.lucene.index.MultiFields; -import org.apache.lucene.index.Term; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; -import org.apache.lucene.index.TermsEnum.SeekStatus; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.store.Directory; import org.apache.lucene.store.LockObtainFailedException; @@ -798,6 +796,7 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter { // per step) while (otherTaxonomiesLeft>0) { + // TODO: use a pq here String first=null; for (int i=0; i