func()

in pkg/index/inverted/inverted.go [406:470]


func (bmi *blugeMatchIterator) nextTerm() bool {
	var match *search.DocumentMatch
	match, bmi.err = bmi.delegated.Next()
	if bmi.err != nil {
		return false
	}
	if match == nil {
		if bmi.agg == nil {
			bmi.closed = true
		} else {
			bmi.current = bmi.agg
			bmi.agg = nil
		}
		return false
	}
	i := 0
	var docID uint64
	var term []byte
	bmi.err = match.VisitStoredFields(func(field string, value []byte) bool {
		if field == docIDField {
			if len(value) == 8 {
				docID = convert.BytesToUint64(value)
			} else if len(value) == 16 {
				// value = seriesID(8bytes)+docID(8bytes)
				docID = convert.BytesToUint64(value[8:])
			}
			i++
		}
		if field == bmi.fieldKey {
			v := y.Copy(value)
			if bmi.shouldDecodeTerm {
				term = index.UnmarshalTerm(v)
			} else {
				term = v
			}
			i++
		}
		return i < 2
	})
	if i != 2 {
		// ignore invalid data
		// TODO: add metric to cumulate ignored docs
		return true
	}
	if bmi.err != nil {
		return false
	}
	if bmi.agg == nil {
		bmi.agg = &index.PostingValue{
			Term:  term,
			Value: roaring.NewPostingListWithInitialData(docID),
		}
		return true
	}
	if bytes.Equal(bmi.agg.Term, term) {
		bmi.agg.Value.Insert(docID)
		return true
	}
	bmi.current = bmi.agg
	bmi.agg = &index.PostingValue{
		Term:  term,
		Value: roaring.NewPostingListWithInitialData(docID),
	}
	return false
}