scorch zap build reuses mem postingsList/Iterator structs
This commit is contained in:
parent
85761c6a57
commit
8c0881eab2
|
@ -33,12 +33,20 @@ type Dictionary struct {
|
|||
// PostingsList returns the postings list for the specified term
|
||||
func (d *Dictionary) PostingsList(term string,
|
||||
except *roaring.Bitmap) (segment.PostingsList, error) {
|
||||
return &PostingsList{
|
||||
dictionary: d,
|
||||
term: term,
|
||||
postingsID: d.segment.Dicts[d.fieldID][term],
|
||||
except: except,
|
||||
}, nil
|
||||
return d.InitPostingsList(term, except, nil)
|
||||
}
|
||||
|
||||
func (d *Dictionary) InitPostingsList(term string, except *roaring.Bitmap,
|
||||
prealloc *PostingsList) (*PostingsList, error) {
|
||||
rv := prealloc
|
||||
if rv == nil {
|
||||
rv = &PostingsList{}
|
||||
}
|
||||
rv.dictionary = d
|
||||
rv.term = term
|
||||
rv.postingsID = d.segment.Dicts[d.fieldID][term]
|
||||
rv.except = except
|
||||
return rv, nil
|
||||
}
|
||||
|
||||
// Iterator returns an iterator for this dictionary
|
||||
|
|
|
@ -46,9 +46,16 @@ func (p *PostingsList) Count() uint64 {
|
|||
|
||||
// Iterator returns an iterator for this postings list
|
||||
func (p *PostingsList) Iterator() segment.PostingsIterator {
|
||||
rv := &PostingsIterator{
|
||||
postings: p,
|
||||
return p.InitIterator(nil)
|
||||
}
|
||||
func (p *PostingsList) InitIterator(prealloc *PostingsIterator) *PostingsIterator {
|
||||
rv := prealloc
|
||||
if rv == nil {
|
||||
rv = &PostingsIterator{postings: p}
|
||||
} else {
|
||||
*rv = PostingsIterator{postings: p}
|
||||
}
|
||||
|
||||
if p.postingsID > 0 {
|
||||
allbits := p.dictionary.segment.Postings[p.postingsID-1]
|
||||
rv.locations = p.dictionary.segment.PostingsLocs[p.postingsID-1]
|
||||
|
|
|
@ -532,6 +532,9 @@ func persistDocValues(memSegment *mem.Segment, w *CountHashWriter,
|
|||
fieldChunkOffsets := make(map[uint16]uint64, len(memSegment.FieldsInv))
|
||||
fdvEncoder := newChunkedContentCoder(uint64(chunkFactor), uint64(len(memSegment.Stored)-1))
|
||||
|
||||
var postings *mem.PostingsList
|
||||
var postingsItr *mem.PostingsIterator
|
||||
|
||||
for fieldID := range memSegment.DocValueFields {
|
||||
field := memSegment.FieldsInv[fieldID]
|
||||
docTermMap := make(map[uint64][]byte, 0)
|
||||
|
@ -543,12 +546,13 @@ func persistDocValues(memSegment *mem.Segment, w *CountHashWriter,
|
|||
dictItr := dict.Iterator()
|
||||
next, err := dictItr.Next()
|
||||
for err == nil && next != nil {
|
||||
postings, err1 := dict.PostingsList(next.Term, nil)
|
||||
var err1 error
|
||||
postings, err1 = dict.(*mem.Dictionary).InitPostingsList(next.Term, nil, postings)
|
||||
if err1 != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
postingsItr := postings.Iterator()
|
||||
postingsItr = postings.InitIterator(postingsItr)
|
||||
nextPosting, err2 := postingsItr.Next()
|
||||
for err2 == nil && nextPosting != nil {
|
||||
docNum := nextPosting.Number()
|
||||
|
|
Loading…
Reference in New Issue