LUCENE-2858: fix grouping module

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene2858@1237325 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-01-29 16:24:30 +00:00
parent 1963304dbe
commit 4ef047b892
17 changed files with 104 additions and 91 deletions

View File

@ -17,7 +17,7 @@ package org.apache.lucene.search.grouping;
* limitations under the License.
*/
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.search.*;
import java.io.IOException;

View File

@ -17,7 +17,7 @@ package org.apache.lucene.search.grouping;
* limitations under the License.
*/
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.search.*;
import java.io.IOException;

View File

@ -20,7 +20,7 @@ package org.apache.lucene.search.grouping;
import java.io.IOException;
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.index.IndexWriter; // javadocs
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.DocIdSetIterator;
@ -505,7 +505,7 @@ public class BlockGroupingCollector extends Collector {
subDocUpto = 0;
docBase = readerContext.docBase;
//System.out.println("setNextReader base=" + docBase + " r=" + readerContext.reader);
lastDocPerGroupBits = lastDocPerGroup.getDocIdSet(readerContext, readerContext.reader.getLiveDocs()).iterator();
lastDocPerGroupBits = lastDocPerGroup.getDocIdSet(readerContext, readerContext.reader().getLiveDocs()).iterator();
groupEndDocID = -1;
currentReaderContext = readerContext;

View File

@ -17,6 +17,7 @@ package org.apache.lucene.search.grouping.dv;
* limitations under the License.
*/
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.DocValues.Type; // javadocs
import org.apache.lucene.index.IndexReader;
@ -43,7 +44,7 @@ public abstract class DVAllGroupHeadsCollector<GH extends AbstractAllGroupHeadsC
final DocValues.Type valueType;
final BytesRef scratchBytesRef = new BytesRef();
IndexReader.AtomicReaderContext readerContext;
AtomicReaderContext readerContext;
Scorer scorer;
DVAllGroupHeadsCollector(String groupField, DocValues.Type valueType, int numberOfSorts, boolean diskResident) {
@ -91,10 +92,10 @@ public abstract class DVAllGroupHeadsCollector<GH extends AbstractAllGroupHeadsC
static class GroupHead extends AbstractAllGroupHeadsCollector.GroupHead<Comparable> {
final FieldComparator[] comparators;
IndexReader.AtomicReaderContext readerContext;
AtomicReaderContext readerContext;
Scorer scorer;
GroupHead(Comparable groupValue, Sort sort, int doc, IndexReader.AtomicReaderContext readerContext, Scorer scorer) throws IOException {
GroupHead(Comparable groupValue, Sort sort, int doc, AtomicReaderContext readerContext, Scorer scorer) throws IOException {
super(groupValue, doc + readerContext.docBase);
final SortField[] sortFields = sort.getSort();
comparators = new FieldComparator[sortFields.length];
@ -123,10 +124,10 @@ public abstract class DVAllGroupHeadsCollector<GH extends AbstractAllGroupHeadsC
}
@Override
public void setNextReader(IndexReader.AtomicReaderContext readerContext) throws IOException {
public void setNextReader(AtomicReaderContext readerContext) throws IOException {
this.readerContext = readerContext;
final DocValues dv = readerContext.reader.docValues(groupField);
final DocValues dv = readerContext.reader().docValues(groupField);
final DocValues.Source dvSource;
if (dv != null) {
dvSource = diskResident ? dv.getDirectSource() : dv.getSource();
@ -147,7 +148,7 @@ public abstract class DVAllGroupHeadsCollector<GH extends AbstractAllGroupHeadsC
* @return The default source when no doc values are available.
* @param readerContext The current reader context
*/
protected DocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) {
protected DocValues.Source getDefaultSource(AtomicReaderContext readerContext) {
return DocValues.getDefaultSource(valueType);
}
@ -189,7 +190,7 @@ public abstract class DVAllGroupHeadsCollector<GH extends AbstractAllGroupHeadsC
return groups.values();
}
public void setNextReader(IndexReader.AtomicReaderContext context) throws IOException {
public void setNextReader(AtomicReaderContext context) throws IOException {
super.setNextReader(context);
for (GroupHead groupHead : groups.values()) {
for (int i = 0; i < groupHead.comparators.length; i++) {
@ -230,8 +231,8 @@ public abstract class DVAllGroupHeadsCollector<GH extends AbstractAllGroupHeadsC
}
@Override
protected DocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) {
return DocValues.getDefaultSortedSource(valueType, readerContext.reader.maxDoc());
protected DocValues.Source getDefaultSource(AtomicReaderContext readerContext) {
return DocValues.getDefaultSortedSource(valueType, readerContext.reader().maxDoc());
}
}

View File

@ -17,6 +17,7 @@ package org.apache.lucene.search.grouping.dv;
* limitations under the License.
*/
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.DocValues.Type; // javadocs
import org.apache.lucene.index.IndexReader;
@ -104,8 +105,8 @@ public abstract class DVAllGroupsCollector<GROUP_VALUE_TYPE> extends AbstractAll
}
@Override
public void setNextReader(IndexReader.AtomicReaderContext readerContext) throws IOException {
final DocValues dv = readerContext.reader.docValues(groupField);
public void setNextReader(AtomicReaderContext readerContext) throws IOException {
final DocValues dv = readerContext.reader().docValues(groupField);
final DocValues.Source dvSource;
if (dv != null) {
dvSource = diskResident ? dv.getDirectSource() : dv.getSource();
@ -121,13 +122,13 @@ public abstract class DVAllGroupsCollector<GROUP_VALUE_TYPE> extends AbstractAll
* @param source The idv source to be used by concrete implementations
* @param readerContext The current reader context
*/
protected abstract void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext);
protected abstract void setDocValuesSources(DocValues.Source source, AtomicReaderContext readerContext);
/**
* @return The default source when no doc values are available.
* @param readerContext The current reader context
*/
protected DocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) {
protected DocValues.Source getDefaultSource(AtomicReaderContext readerContext) {
return DocValues.getDefaultSource(valueType);
}
@ -150,7 +151,7 @@ public abstract class DVAllGroupsCollector<GROUP_VALUE_TYPE> extends AbstractAll
return groups;
}
protected void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext) {
protected void setDocValuesSources(DocValues.Source source, AtomicReaderContext readerContext) {
this.source = source;
}
@ -175,7 +176,7 @@ public abstract class DVAllGroupsCollector<GROUP_VALUE_TYPE> extends AbstractAll
return groups;
}
protected void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext) {
protected void setDocValuesSources(DocValues.Source source, AtomicReaderContext readerContext) {
this.source = source;
}
@ -202,7 +203,7 @@ public abstract class DVAllGroupsCollector<GROUP_VALUE_TYPE> extends AbstractAll
return groups;
}
protected void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext) {
protected void setDocValuesSources(DocValues.Source source, AtomicReaderContext readerContext) {
this.source = source;
}
@ -233,7 +234,7 @@ public abstract class DVAllGroupsCollector<GROUP_VALUE_TYPE> extends AbstractAll
return groups;
}
protected void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext) {
protected void setDocValuesSources(DocValues.Source source, AtomicReaderContext readerContext) {
this.source = source.asSortedSource();
ordSet.clear();
@ -246,8 +247,8 @@ public abstract class DVAllGroupsCollector<GROUP_VALUE_TYPE> extends AbstractAll
}
@Override
protected DocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) {
return DocValues.getDefaultSortedSource(valueType, readerContext.reader.maxDoc());
protected DocValues.Source getDefaultSource(AtomicReaderContext readerContext) {
return DocValues.getDefaultSortedSource(valueType, readerContext.reader().maxDoc());
}
}

View File

@ -17,6 +17,7 @@ package org.apache.lucene.search.grouping.dv;
* limitations under the License.
*/
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.DocValues.Type; // javadocs
import org.apache.lucene.index.IndexReader;
@ -69,10 +70,10 @@ public abstract class DVFirstPassGroupingCollector<GROUP_VALUE_TYPE> extends Abs
}
@Override
public void setNextReader(IndexReader.AtomicReaderContext readerContext) throws IOException {
public void setNextReader(AtomicReaderContext readerContext) throws IOException {
super.setNextReader(readerContext);
final DocValues dv = readerContext.reader.docValues(groupField);
final DocValues dv = readerContext.reader().docValues(groupField);
final DocValues.Source dvSource;
if (dv != null) {
dvSource = diskResident ? dv.getDirectSource() : dv.getSource();
@ -93,7 +94,7 @@ public abstract class DVFirstPassGroupingCollector<GROUP_VALUE_TYPE> extends Abs
* @return The default source when no doc values are available.
* @param readerContext The current reader context
*/
protected DocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) {
protected DocValues.Source getDefaultSource(AtomicReaderContext readerContext) {
return DocValues.getDefaultSource(valueType);
}
@ -197,8 +198,8 @@ public abstract class DVFirstPassGroupingCollector<GROUP_VALUE_TYPE> extends Abs
}
@Override
protected DocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) {
return DocValues.getDefaultSortedSource(valueType, readerContext.reader.maxDoc());
protected DocValues.Source getDefaultSource(AtomicReaderContext readerContext) {
return DocValues.getDefaultSortedSource(valueType, readerContext.reader().maxDoc());
}
}

View File

@ -17,6 +17,7 @@ package org.apache.lucene.search.grouping.dv;
* limitations under the License.
*/
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.DocValues.Type; // javadocs
import org.apache.lucene.index.IndexReader;
@ -103,10 +104,10 @@ public abstract class DVSecondPassGroupingCollector<GROUP_VALUE> extends Abstrac
}
@Override
public void setNextReader(IndexReader.AtomicReaderContext readerContext) throws IOException {
public void setNextReader(AtomicReaderContext readerContext) throws IOException {
super.setNextReader(readerContext);
final DocValues dv = readerContext.reader.docValues(groupField);
final DocValues dv = readerContext.reader().docValues(groupField);
final DocValues.Source dvSource;
if (dv != null) {
dvSource = diskResident ? dv.getDirectSource() : dv.getSource();
@ -122,13 +123,13 @@ public abstract class DVSecondPassGroupingCollector<GROUP_VALUE> extends Abstrac
* @param source The idv source to be used by concrete implementations
* @param readerContext The current reader context
*/
protected abstract void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext);
protected abstract void setDocValuesSources(DocValues.Source source, AtomicReaderContext readerContext);
/**
* @return The default source when no doc values are available.
* @param readerContext The current reader context
*/
protected DocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) {
protected DocValues.Source getDefaultSource(AtomicReaderContext readerContext) {
return DocValues.getDefaultSource(valueType);
}
@ -144,7 +145,7 @@ public abstract class DVSecondPassGroupingCollector<GROUP_VALUE> extends Abstrac
return groupMap.get(source.getInt(doc));
}
protected void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext) {
protected void setDocValuesSources(DocValues.Source source, AtomicReaderContext readerContext) {
this.source = source;
}
}
@ -161,7 +162,7 @@ public abstract class DVSecondPassGroupingCollector<GROUP_VALUE> extends Abstrac
return groupMap.get(source.getFloat(doc));
}
protected void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext) {
protected void setDocValuesSources(DocValues.Source source, AtomicReaderContext readerContext) {
this.source = source;
}
}
@ -180,7 +181,7 @@ public abstract class DVSecondPassGroupingCollector<GROUP_VALUE> extends Abstrac
}
@Override
protected void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext) {
protected void setDocValuesSources(DocValues.Source source, AtomicReaderContext readerContext) {
this.source = source;
}
@ -209,7 +210,7 @@ public abstract class DVSecondPassGroupingCollector<GROUP_VALUE> extends Abstrac
}
@Override
protected void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext) {
protected void setDocValuesSources(DocValues.Source source, AtomicReaderContext readerContext) {
this.source = source.asSortedSource();
ordSet.clear();
@ -222,8 +223,8 @@ public abstract class DVSecondPassGroupingCollector<GROUP_VALUE> extends Abstrac
}
@Override
protected DocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) {
return DocValues.getDefaultSortedSource(valueType, readerContext.reader.maxDoc());
protected DocValues.Source getDefaultSource(AtomicReaderContext readerContext) {
return DocValues.getDefaultSortedSource(valueType, readerContext.reader().maxDoc());
}
}

View File

@ -17,6 +17,7 @@ package org.apache.lucene.search.grouping.function;
* limitations under the License.
*/
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.ValueSource;
@ -47,7 +48,7 @@ public class FunctionAllGroupHeadsCollector extends AbstractAllGroupHeadsCollect
private FunctionValues.ValueFiller filler;
private MutableValue mval;
private IndexReader.AtomicReaderContext readerContext;
private AtomicReaderContext readerContext;
private Scorer scorer;
/**
@ -103,7 +104,7 @@ public class FunctionAllGroupHeadsCollector extends AbstractAllGroupHeadsCollect
}
}
public void setNextReader(IndexReader.AtomicReaderContext context) throws IOException {
public void setNextReader(AtomicReaderContext context) throws IOException {
this.readerContext = context;
FunctionValues docValues = groupBy.getValues(vsContext, context);
filler = docValues.getValueFiller();

View File

@ -17,6 +17,7 @@ package org.apache.lucene.search.grouping.function;
* limitations under the License.
*/
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.ValueSource;
@ -78,7 +79,7 @@ public class FunctionAllGroupsCollector extends AbstractAllGroupsCollector<Mutab
/**
* {@inheritDoc}
*/
public void setNextReader(IndexReader.AtomicReaderContext context) throws IOException {
public void setNextReader(AtomicReaderContext context) throws IOException {
FunctionValues docValues = groupBy.getValues(vsContext, context);
filler = docValues.getValueFiller();
mval = filler.getValue();

View File

@ -17,6 +17,7 @@ package org.apache.lucene.search.grouping.function;
* limitations under the License.
*/
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.ValueSource;
@ -78,7 +79,7 @@ public class FunctionFirstPassGroupingCollector extends AbstractFirstPassGroupin
}
@Override
public void setNextReader(IndexReader.AtomicReaderContext readerContext) throws IOException {
public void setNextReader(AtomicReaderContext readerContext) throws IOException {
super.setNextReader(readerContext);
docValues = groupByVS.getValues(vsContext, readerContext);
filler = docValues.getValueFiller();

View File

@ -17,6 +17,7 @@ package org.apache.lucene.search.grouping.function;
* limitations under the License.
*/
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.ValueSource;
@ -75,7 +76,7 @@ public class FunctionSecondPassGroupingCollector extends AbstractSecondPassGroup
/**
* {@inheritDoc}
*/
public void setNextReader(IndexReader.AtomicReaderContext readerContext) throws IOException {
public void setNextReader(AtomicReaderContext readerContext) throws IOException {
super.setNextReader(readerContext);
FunctionValues docValues = groupByVS.getValues(vsContext, readerContext);
filler = docValues.getValueFiller();

View File

@ -17,6 +17,7 @@ package org.apache.lucene.search.grouping.term;
* limitations under the License.
*/
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.*;
import org.apache.lucene.search.grouping.AbstractAllGroupHeadsCollector;
@ -41,7 +42,7 @@ public abstract class TermAllGroupHeadsCollector<GH extends AbstractAllGroupHead
final BytesRef scratchBytesRef = new BytesRef();
FieldCache.DocTermsIndex groupIndex;
IndexReader.AtomicReaderContext readerContext;
AtomicReaderContext readerContext;
protected TermAllGroupHeadsCollector(String groupField, int numberOfSorts) {
super(numberOfSorts);
@ -142,9 +143,9 @@ public abstract class TermAllGroupHeadsCollector<GH extends AbstractAllGroupHead
return groups.values();
}
public void setNextReader(IndexReader.AtomicReaderContext context) throws IOException {
public void setNextReader(AtomicReaderContext context) throws IOException {
this.readerContext = context;
groupIndex = FieldCache.DEFAULT.getTermsIndex(context.reader, groupField);
groupIndex = FieldCache.DEFAULT.getTermsIndex(context.reader(), groupField);
for (GroupHead groupHead : groups.values()) {
for (int i = 0; i < groupHead.comparators.length; i++) {
@ -243,15 +244,15 @@ public abstract class TermAllGroupHeadsCollector<GH extends AbstractAllGroupHead
temporalResult.groupHead = groupHead;
}
public void setNextReader(IndexReader.AtomicReaderContext context) throws IOException {
public void setNextReader(AtomicReaderContext context) throws IOException {
this.readerContext = context;
groupIndex = FieldCache.DEFAULT.getTermsIndex(context.reader, groupField);
groupIndex = FieldCache.DEFAULT.getTermsIndex(context.reader(), groupField);
for (int i = 0; i < fields.length; i++) {
if (fields[i].getType() == SortField.Type.SCORE) {
continue;
}
sortsIndex[i] = FieldCache.DEFAULT.getTermsIndex(context.reader, fields[i].getField());
sortsIndex[i] = FieldCache.DEFAULT.getTermsIndex(context.reader(), fields[i].getField());
}
// Clear ordSet and fill it with previous encountered groups that can occur in the current segment.
@ -380,11 +381,11 @@ public abstract class TermAllGroupHeadsCollector<GH extends AbstractAllGroupHead
temporalResult.groupHead = groupHead;
}
public void setNextReader(IndexReader.AtomicReaderContext context) throws IOException {
public void setNextReader(AtomicReaderContext context) throws IOException {
this.readerContext = context;
groupIndex = FieldCache.DEFAULT.getTermsIndex(context.reader, groupField);
groupIndex = FieldCache.DEFAULT.getTermsIndex(context.reader(), groupField);
for (int i = 0; i < fields.length; i++) {
sortsIndex[i] = FieldCache.DEFAULT.getTermsIndex(context.reader, fields[i].getField());
sortsIndex[i] = FieldCache.DEFAULT.getTermsIndex(context.reader(), fields[i].getField());
}
// Clear ordSet and fill it with previous encountered groups that can occur in the current segment.
@ -488,9 +489,9 @@ public abstract class TermAllGroupHeadsCollector<GH extends AbstractAllGroupHead
temporalResult.groupHead = groupHead;
}
public void setNextReader(IndexReader.AtomicReaderContext context) throws IOException {
public void setNextReader(AtomicReaderContext context) throws IOException {
this.readerContext = context;
groupIndex = FieldCache.DEFAULT.getTermsIndex(context.reader, groupField);
groupIndex = FieldCache.DEFAULT.getTermsIndex(context.reader(), groupField);
// Clear ordSet and fill it with previous encountered groups that can occur in the current segment.
ordSet.clear();

View File

@ -17,6 +17,7 @@ package org.apache.lucene.search.grouping.term;
* limitations under the License.
*/
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.FieldCache;
import org.apache.lucene.search.grouping.AbstractAllGroupsCollector;
@ -97,8 +98,8 @@ public class TermAllGroupsCollector extends AbstractAllGroupsCollector<BytesRef>
return groups;
}
public void setNextReader(IndexReader.AtomicReaderContext context) throws IOException {
index = FieldCache.DEFAULT.getTermsIndex(context.reader, groupField);
public void setNextReader(AtomicReaderContext context) throws IOException {
index = FieldCache.DEFAULT.getTermsIndex(context.reader(), groupField);
// Clear ordSet and fill it with previous encountered groups that can occur in the current segment.
ordSet.clear();

View File

@ -17,7 +17,7 @@ package org.apache.lucene.search.grouping.term;
* limitations under the License.
*/
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.search.FieldCache;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.grouping.AbstractFirstPassGroupingCollector;
@ -81,6 +81,6 @@ public class TermFirstPassGroupingCollector extends AbstractFirstPassGroupingCol
@Override
public void setNextReader(AtomicReaderContext readerContext) throws IOException {
super.setNextReader(readerContext);
index = FieldCache.DEFAULT.getTermsIndex(readerContext.reader, groupField);
index = FieldCache.DEFAULT.getTermsIndex(readerContext.reader(), groupField);
}
}

View File

@ -17,7 +17,7 @@ package org.apache.lucene.search.grouping.term;
* limitations under the License.
*/
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.search.FieldCache;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.grouping.AbstractSecondPassGroupingCollector;
@ -55,7 +55,7 @@ public class TermSecondPassGroupingCollector extends AbstractSecondPassGroupingC
@Override
public void setNextReader(AtomicReaderContext readerContext) throws IOException {
super.setNextReader(readerContext);
index = FieldCache.DEFAULT.getTermsIndex(readerContext.reader, groupField);
index = FieldCache.DEFAULT.getTermsIndex(readerContext.reader(), groupField);
// Rebuild ordSet
ordSet.clear();

View File

@ -19,9 +19,10 @@ package org.apache.lucene.search.grouping;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.*;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.SlowMultiReaderWrapper;
import org.apache.lucene.index.SlowCompositeReaderWrapper;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.DocValues.Type;
import org.apache.lucene.queries.function.ValueSource;
@ -113,7 +114,7 @@ public class AllGroupHeadsCollectorTest extends LuceneTestCase {
IndexReader reader = w.getReader();
IndexSearcher indexSearcher = new IndexSearcher(reader);
if (SlowMultiReaderWrapper.class.isAssignableFrom(reader.getClass())) {
if (SlowCompositeReaderWrapper.class.isAssignableFrom(reader.getClass())) {
canUseIDV = false;
}
@ -272,11 +273,11 @@ public class AllGroupHeadsCollectorTest extends LuceneTestCase {
}
}
final IndexReader r = w.getReader();
final DirectoryReader r = w.getReader();
w.close();
// NOTE: intentional but temporary field cache insanity!
final int[] docIdToFieldId = FieldCache.DEFAULT.getInts(new SlowMultiReaderWrapper(r), "id", false);
final int[] docIdToFieldId = FieldCache.DEFAULT.getInts(new SlowCompositeReaderWrapper(r), "id", false);
final int[] fieldIdToDocID = new int[numDocs];
for (int i = 0; i < docIdToFieldId.length; i++) {
int fieldId = docIdToFieldId[i];
@ -285,7 +286,7 @@ public class AllGroupHeadsCollectorTest extends LuceneTestCase {
try {
final IndexSearcher s = newSearcher(r);
if (SlowMultiReaderWrapper.class.isAssignableFrom(s.getIndexReader().getClass())) {
if (SlowCompositeReaderWrapper.class.isAssignableFrom(s.getIndexReader().getClass())) {
canUseIDV = false;
} else {
canUseIDV = !preFlex;
@ -365,7 +366,7 @@ public class AllGroupHeadsCollectorTest extends LuceneTestCase {
}
}
} finally {
FieldCache.DEFAULT.purge(r);
// nocommit FieldCache.DEFAULT.purge(r);
}
r.close();

View File

@ -19,10 +19,14 @@ package org.apache.lucene.search.grouping;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.*;
import org.apache.lucene.index.AtomicIndexReader;
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.index.CompositeIndexReader;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.FieldInfo.IndexOptions;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.SlowMultiReaderWrapper;
import org.apache.lucene.index.SlowCompositeReaderWrapper;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.DocValues.Type;
import org.apache.lucene.queries.function.ValueSource;
@ -553,7 +557,7 @@ public class TestGrouping extends LuceneTestCase {
}
}
private IndexReader getDocBlockReader(Directory dir, GroupDoc[] groupDocs) throws IOException {
private DirectoryReader getDocBlockReader(Directory dir, GroupDoc[] groupDocs) throws IOException {
// Coalesce by group, but in random order:
Collections.shuffle(Arrays.asList(groupDocs), random);
final Map<BytesRef,List<GroupDoc>> groupMap = new HashMap<BytesRef,List<GroupDoc>>();
@ -610,7 +614,7 @@ public class TestGrouping extends LuceneTestCase {
w.updateDocuments(new Term("group", docs.get(0).get("group")), docs);
}
final IndexReader r = w.getReader();
final DirectoryReader r = w.getReader();
w.close();
return r;
@ -622,19 +626,17 @@ public class TestGrouping extends LuceneTestCase {
public final int[] docStarts;
public ShardState(IndexSearcher s) {
IndexReader[] subReaders = s.getIndexReader().getSequentialSubReaders();
if (subReaders == null) {
subReaders = new IndexReader[] {s.getIndexReader()};
}
subSearchers = new ShardSearcher[subReaders.length];
List<AtomicIndexReader> subReaders = new ArrayList<AtomicIndexReader>();
ReaderUtil.gatherSubReaders(subReaders, s.getIndexReader());
subSearchers = new ShardSearcher[subReaders.size()];
final IndexReader.ReaderContext ctx = s.getTopReaderContext();
if (ctx instanceof IndexReader.AtomicReaderContext) {
if (ctx instanceof AtomicReaderContext) {
assert subSearchers.length == 1;
subSearchers[0] = new ShardSearcher((IndexReader.AtomicReaderContext) ctx, ctx);
subSearchers[0] = new ShardSearcher((AtomicReaderContext) ctx, ctx);
} else {
final IndexReader.CompositeReaderContext compCTX = (IndexReader.CompositeReaderContext) ctx;
final CompositeIndexReader.CompositeReaderContext compCTX = (CompositeIndexReader.CompositeReaderContext) ctx;
for(int searcherIDX=0;searcherIDX<subSearchers.length;searcherIDX++) {
subSearchers[searcherIDX] = new ShardSearcher(compCTX.leaves[searcherIDX], compCTX);
subSearchers[searcherIDX] = new ShardSearcher(compCTX.leaves()[searcherIDX], compCTX);
}
}
@ -642,7 +644,7 @@ public class TestGrouping extends LuceneTestCase {
int docBase = 0;
for(int subIDX=0;subIDX<docStarts.length;subIDX++) {
docStarts[subIDX] = docBase;
docBase += subReaders[subIDX].maxDoc();
docBase += subReaders.get(subIDX).maxDoc();
//System.out.println("docStarts[" + subIDX + "]=" + docStarts[subIDX]);
}
}
@ -762,17 +764,17 @@ public class TestGrouping extends LuceneTestCase {
final GroupDoc[] groupDocsByID = new GroupDoc[groupDocs.length];
System.arraycopy(groupDocs, 0, groupDocsByID, 0, groupDocs.length);
final IndexReader r = w.getReader();
final DirectoryReader r = w.getReader();
w.close();
// NOTE: intentional but temporary field cache insanity!
final int[] docIDToID = FieldCache.DEFAULT.getInts(new SlowMultiReaderWrapper(r), "id", false);
IndexReader rBlocks = null;
final int[] docIDToID = FieldCache.DEFAULT.getInts(new SlowCompositeReaderWrapper(r), "id", false);
DirectoryReader rBlocks = null;
Directory dirBlocks = null;
try {
final IndexSearcher s = newSearcher(r);
if (SlowMultiReaderWrapper.class.isAssignableFrom(s.getIndexReader().getClass())) {
if (SlowCompositeReaderWrapper.class.isAssignableFrom(s.getIndexReader().getClass())) {
canUseIDV = false;
} else {
canUseIDV = !preFlex;
@ -799,7 +801,7 @@ public class TestGrouping extends LuceneTestCase {
dirBlocks = newDirectory();
rBlocks = getDocBlockReader(dirBlocks, groupDocs);
final Filter lastDocInBlock = new CachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("groupend", "x"))));
final int[] docIDToIDBlocks = FieldCache.DEFAULT.getInts(new SlowMultiReaderWrapper(rBlocks), "id", false);
final int[] docIDToIDBlocks = FieldCache.DEFAULT.getInts(new SlowCompositeReaderWrapper(rBlocks), "id", false);
final IndexSearcher sBlocks = newSearcher(rBlocks);
final ShardState shardsBlocks = new ShardState(sBlocks);
@ -1138,9 +1140,9 @@ public class TestGrouping extends LuceneTestCase {
assertEquals(docIDToIDBlocks, expectedGroups, topGroupsBlockShards, false, false, fillFields, getScores, false);
}
} finally {
FieldCache.DEFAULT.purge(r);
// nocommit FieldCache.DEFAULT.purge(r);
if (rBlocks != null) {
FieldCache.DEFAULT.purge(rBlocks);
// nocommit FieldCache.DEFAULT.purge(rBlocks);
}
}
@ -1177,7 +1179,7 @@ public class TestGrouping extends LuceneTestCase {
List<AbstractFirstPassGroupingCollector> firstPassGroupingCollectors = new ArrayList<AbstractFirstPassGroupingCollector>();
AbstractFirstPassGroupingCollector firstPassCollector = null;
for(int shardIDX=0;shardIDX<subSearchers.length;shardIDX++) {
if (SlowMultiReaderWrapper.class.isAssignableFrom(subSearchers[shardIDX].getIndexReader().getClass())) {
if (SlowCompositeReaderWrapper.class.isAssignableFrom(subSearchers[shardIDX].getIndexReader().getClass())) {
canUseIDV = false;
} else {
canUseIDV = !preFlex;
@ -1311,11 +1313,11 @@ public class TestGrouping extends LuceneTestCase {
}
private static class ShardSearcher extends IndexSearcher {
private final IndexReader.AtomicReaderContext[] ctx;
private final AtomicReaderContext[] ctx;
public ShardSearcher(IndexReader.AtomicReaderContext ctx, IndexReader.ReaderContext parent) {
public ShardSearcher(AtomicReaderContext ctx, IndexReader.ReaderContext parent) {
super(parent);
this.ctx = new IndexReader.AtomicReaderContext[] {ctx};
this.ctx = new AtomicReaderContext[] {ctx};
}
public void search(Weight weight, Collector collector) throws IOException {
@ -1328,7 +1330,7 @@ public class TestGrouping extends LuceneTestCase {
@Override
public String toString() {
return "ShardSearcher(" + ctx[0].reader + ")";
return "ShardSearcher(" + ctx[0].reader() + ")";
}
}