From 1a68f4b67c203776c0004714990da923d13f1bae Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Mon, 12 Oct 2015 19:34:33 +0000 Subject: [PATCH] LUCENE-6836: Fix reader context management with block-join sorting. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1708209 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/search/BlockJoinComparatorSource.java | 3 ++- .../org/apache/lucene/index/TestBlockJoinSorter.java | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lucene/misc/src/java/org/apache/lucene/search/BlockJoinComparatorSource.java b/lucene/misc/src/java/org/apache/lucene/search/BlockJoinComparatorSource.java index e0b9f1962b0..d0ac72209e2 100644 --- a/lucene/misc/src/java/org/apache/lucene/search/BlockJoinComparatorSource.java +++ b/lucene/misc/src/java/org/apache/lucene/search/BlockJoinComparatorSource.java @@ -20,6 +20,7 @@ package org.apache.lucene.search; import java.io.IOException; import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.index.ReaderUtil; import org.apache.lucene.index.SortingMergePolicy; import org.apache.lucene.util.BitSet; @@ -118,7 +119,7 @@ public class BlockJoinComparatorSource extends FieldComparatorSource { if (parentBits != null) { throw new IllegalStateException("This comparator can only be used on a single segment"); } - IndexSearcher searcher = new IndexSearcher(context.reader()); + IndexSearcher searcher = new IndexSearcher(ReaderUtil.getTopLevelContext(context)); searcher.setQueryCache(null); final Weight weight = searcher.createNormalizedWeight(parentsFilter, false); final DocIdSetIterator parents = weight.scorer(context); diff --git a/lucene/misc/src/test/org/apache/lucene/index/TestBlockJoinSorter.java b/lucene/misc/src/test/org/apache/lucene/index/TestBlockJoinSorter.java index 6e63f790bf1..c6d50feeaef 100644 --- a/lucene/misc/src/test/org/apache/lucene/index/TestBlockJoinSorter.java +++ b/lucene/misc/src/test/org/apache/lucene/index/TestBlockJoinSorter.java @@ -41,7 +41,6 @@ import org.junit.Ignore; public class TestBlockJoinSorter extends LuceneTestCase { - @AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/LUCENE-6836") public void test() throws IOException { final int numParents = atLeast(200); IndexWriterConfig cfg = newIndexWriterConfig(new MockAnalyzer(random())); @@ -65,14 +64,17 @@ public class TestBlockJoinSorter extends LuceneTestCase { writer.addDocuments(documents); } writer.forceMerge(1); - final DirectoryReader indexReader = writer.getReader(); + IndexReader indexReader = writer.getReader(); writer.close(); - final LeafReader reader = getOnlySegmentReader(indexReader); + IndexSearcher searcher = newSearcher(indexReader); + indexReader = searcher.getIndexReader(); // newSearcher may have wrapped it + assertEquals(1, indexReader.leaves().size()); + final LeafReader reader = indexReader.leaves().get(0).reader(); final Query parentsFilter = new TermQuery(new Term("parent", "true")); - IndexSearcher searcher = newSearcher(reader); + final Weight weight = searcher.createNormalizedWeight(parentsFilter, false); - final DocIdSetIterator parents = weight.scorer(reader.getContext()); + final DocIdSetIterator parents = weight.scorer(indexReader.leaves().get(0)); final BitSet parentBits = BitSet.of(parents, reader.maxDoc()); final NumericDocValues parentValues = reader.getNumericDocValues("parent_val"); final NumericDocValues childValues = reader.getNumericDocValues("child_val");