DocTermOrds requires atomic reader

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1236443 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2012-01-26 23:20:10 +00:00
parent 9469e0e0a7
commit c56e845c68
4 changed files with 24 additions and 12 deletions

View File

@ -68,6 +68,8 @@ import java.util.Comparator;
*
* The RAM consumption of this class can be high!
*
* <p>NOTE: the provided reader must be an atomic reader
*
* @lucene.experimental
*/
@ -200,12 +202,16 @@ public class DocTermOrds {
}
if (indexedTermsArray == null) {
//System.out.println("GET normal enum");
final Terms terms = MultiFields.getTerms(reader, field);
if (terms != null) {
return terms.iterator(null);
} else {
final Fields fields = reader.fields();
if (fields == null) {
return null;
}
final Terms terms = fields.terms(field);
if (terms == null) {
return null;
} else {
return terms.iterator(null);
}
} else {
//System.out.println("GET wrapped enum ordBase=" + ordBase);
return new OrdWrappedTermsEnum(reader);
@ -230,7 +236,12 @@ public class DocTermOrds {
final int[] lastTerm = new int[maxDoc]; // last term we saw for this document
final byte[][] bytes = new byte[maxDoc][]; // list of term numbers for the doc (delta encoded vInts)
final Terms terms = MultiFields.getTerms(reader, field);
final Fields fields = reader.fields();
if (fields == null) {
// No terms
return;
}
final Terms terms = fields.terms(field);
if (terms == null) {
// No terms
return;
@ -251,7 +262,7 @@ public class DocTermOrds {
boolean testedOrd = false;
final Bits liveDocs = MultiFields.getLiveDocs(reader);
final Bits liveDocs = reader.getLiveDocs();
// we need a minimum of 9 bytes, but round up to 12 since the space would
// be wasted with most allocators anyway.
@ -641,7 +652,7 @@ public class DocTermOrds {
public OrdWrappedTermsEnum(IndexReader reader) throws IOException {
this.reader = reader;
assert indexedTermsArray != null;
termsEnum = MultiFields.getTerms(reader, field).iterator(null);
termsEnum = reader.fields().terms(field).iterator(null);
}
@Override

View File

@ -66,7 +66,7 @@ public class TestDocTermOrds extends LuceneTestCase {
final IndexReader r = w.getReader();
w.close();
final DocTermOrds dto = new DocTermOrds(r, "field");
final DocTermOrds dto = new DocTermOrds(new SlowMultiReaderWrapper(r), "field");
TermOrdsIterator iter = dto.lookup(0, null);
final int[] buffer = new int[5];

View File

@ -175,7 +175,7 @@ public class UnInvertedField extends DocTermOrds {
final String prefix = TrieField.getMainValuePrefix(searcher.getSchema().getFieldType(field));
this.searcher = searcher;
try {
uninvert(searcher.getIndexReader(), prefix == null ? null : new BytesRef(prefix));
uninvert(new SlowMultiReaderWrapper(searcher.getIndexReader()), prefix == null ? null : new BytesRef(prefix));
} catch (IllegalStateException ise) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, ise.getMessage());
}
@ -227,7 +227,7 @@ public class UnInvertedField extends DocTermOrds {
int startTerm = 0;
int endTerm = numTermsInField; // one past the end
TermsEnum te = getOrdTermsEnum(searcher.getIndexReader());
TermsEnum te = getOrdTermsEnum(new SlowMultiReaderWrapper(searcher.getIndexReader()));
if (prefix != null && prefix.length() > 0) {
final BytesRef prefixBr = new BytesRef(prefix);
if (te.seekCeil(prefixBr, true) == TermsEnum.SeekStatus.END) {
@ -497,7 +497,7 @@ public class UnInvertedField extends DocTermOrds {
final int[] index = this.index;
final int[] counts = new int[numTermsInField];//keep track of the number of times we see each word in the field for all the documents in the docset
TermsEnum te = getOrdTermsEnum(searcher.getIndexReader());
TermsEnum te = getOrdTermsEnum(new SlowMultiReaderWrapper(searcher.getIndexReader()));
boolean doNegative = false;
if (finfo.length == 0) {

View File

@ -21,6 +21,7 @@ import java.util.Locale;
import java.util.Random;
import org.apache.lucene.index.DocTermOrds;
import org.apache.lucene.index.SlowMultiReaderWrapper;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.util.BytesRef;
@ -80,7 +81,7 @@ public class TestFaceting extends SolrTestCaseJ4 {
assertEquals(size, uif.getNumTerms());
TermsEnum te = uif.getOrdTermsEnum(req.getSearcher().getIndexReader());
TermsEnum te = uif.getOrdTermsEnum(new SlowMultiReaderWrapper(req.getSearcher().getIndexReader()));
assertEquals(size == 0, te == null);
Random r = new Random(size);