0
0
Fork 0

issue 441 - upside_down termFieldReader doesn't call Next() early

This change to upside_down term-field-reader no longer moves the
underlying iterator forward preemptively.  Instead, it will invoke
Next() on the underlying iterator only when the caller invokes the
term-field-reader's Next().

There's a special case to handle the situation on the first Next()
invocation after the term-field-reader is created.
This commit is contained in:
Steve Yen 2016-09-22 09:14:46 -07:00
parent 47a98fcf1b
commit bcec199c89
1 changed files with 8 additions and 3 deletions

View File

@ -57,7 +57,6 @@ func newUpsideDownCouchTermFieldReader(indexReader *IndexReader, term []byte, fi
iterator: it,
count: dictionaryRow.count,
term: term,
tfrNext: &TermFrequencyRow{},
field: field,
}, nil
}
@ -68,6 +67,14 @@ func (r *UpsideDownCouchTermFieldReader) Count() uint64 {
func (r *UpsideDownCouchTermFieldReader) Next(preAlloced *index.TermFieldDoc) (*index.TermFieldDoc, error) {
if r.iterator != nil {
// We treat tfrNext also like an initialization flag, which
// tells us whether we need to invoke the underlying
// iterator.Next(). The first time, don't call iterator.Next().
if r.tfrNext != nil {
r.iterator.Next()
} else {
r.tfrNext = &TermFrequencyRow{}
}
key, val, valid := r.iterator.Current()
if valid {
tfr := r.tfrNext
@ -89,7 +96,6 @@ func (r *UpsideDownCouchTermFieldReader) Next(preAlloced *index.TermFieldDoc) (*
if tfr.vectors != nil {
rv.Vectors = r.indexReader.index.termFieldVectorsFromTermVectors(tfr.vectors)
}
r.iterator.Next()
return rv, nil
}
}
@ -116,7 +122,6 @@ func (r *UpsideDownCouchTermFieldReader) Advance(docID index.IndexInternalID, pr
if tfr.vectors != nil {
rv.Vectors = r.indexReader.index.termFieldVectorsFromTermVectors(tfr.vectors)
}
r.iterator.Next()
return rv, nil
}
}