From 19c70cab54c2ca4c1494e4da93cc49da4e0211d9 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Mon, 6 Apr 2015 14:22:49 +0000 Subject: [PATCH] LUCENE-6395: MemoryIndex's TermsEnum.seekExact(long ord) was failing to set the term bytes git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1671540 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 3 +++ .../apache/lucene/index/memory/MemoryIndex.java | 1 + .../lucene/index/memory/TestMemoryIndex.java | 17 ++++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index f68da29c8c2..204678536f6 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -139,6 +139,9 @@ Bug Fixes that up to 3X (X = current index size) spare disk space may be needed to complete forceMerge(1). (Robert Muir, Shai Erera, Mike McCandless) +* LUCENE-6395: Seeking by term ordinal was failing to set the term's + bytes in MemoryIndex (Mike McCandless) + Optimizations * LUCENE-6183, LUCENE-5647: Avoid recompressing stored fields diff --git a/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java b/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java index c7903f5f0fa..5e943d75ea9 100644 --- a/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java +++ b/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java @@ -949,6 +949,7 @@ public class MemoryIndex { public void seekExact(long ord) { assert ord < info.terms.size(); termUpto = (int) ord; + info.terms.get(info.sortedTerms[termUpto], br); } @Override diff --git a/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndex.java b/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndex.java index ed1bee13044..450a6837bd9 100644 --- a/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndex.java +++ b/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndex.java @@ -17,10 +17,13 @@ package org.apache.lucene.index.memory; * limitations under the License. */ +import java.io.IOException; + import org.apache.lucene.analysis.MockAnalyzer; -import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.FieldInvertState; +import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.Term; +import org.apache.lucene.index.TermsEnum; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.TermQuery; @@ -30,8 +33,6 @@ import org.apache.lucene.util.LuceneTestCase; import org.junit.Before; import org.junit.Test; -import java.io.IOException; - import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.junit.internal.matchers.StringContains.containsString; @@ -90,6 +91,16 @@ public class TestMemoryIndex extends LuceneTestCase { } + public void testSeekByTermOrd() throws IOException { + MemoryIndex mi = new MemoryIndex(); + mi.addField("field", "some terms be here", analyzer); + IndexSearcher searcher = mi.createSearcher(); + LeafReader reader = (LeafReader) searcher.getIndexReader(); + TermsEnum terms = reader.fields().terms("field").iterator(null); + terms.seekExact(0); + assertEquals("be", terms.term().utf8ToString()); + } + @Test public void testSimilarities() throws IOException {