diff --git a/index/scorch/segment/empty.go b/index/scorch/segment/empty.go index 6c19f60f..6fa85f65 100644 --- a/index/scorch/segment/empty.go +++ b/index/scorch/segment/empty.go @@ -84,7 +84,7 @@ func (e *EmptyDictionaryIterator) Next() (*index.DictEntry, error) { type EmptyPostingsList struct{} -func (e *EmptyPostingsList) Iterator() PostingsIterator { +func (e *EmptyPostingsList) Iterator(includeFreq, includeNorm, includeLocations bool) PostingsIterator { return &EmptyPostingsIterator{} } diff --git a/index/scorch/segment/mem/posting.go b/index/scorch/segment/mem/posting.go index 4203acbe..362fdb7c 100644 --- a/index/scorch/segment/mem/posting.go +++ b/index/scorch/segment/mem/posting.go @@ -78,7 +78,7 @@ func (p *PostingsList) Count() uint64 { } // Iterator returns an iterator for this postings list -func (p *PostingsList) Iterator() segment.PostingsIterator { +func (p *PostingsList) Iterator(includeFreq, includeNorm, includeLocations bool) segment.PostingsIterator { return p.InitIterator(nil) } func (p *PostingsList) InitIterator(prealloc *PostingsIterator) *PostingsIterator { diff --git a/index/scorch/segment/mem/segment_test.go b/index/scorch/segment/mem/segment_test.go index 6c5625d8..c4c01f14 100644 --- a/index/scorch/segment/mem/segment_test.go +++ b/index/scorch/segment/mem/segment_test.go @@ -48,7 +48,7 @@ func TestEmpty(t *testing.T) { t.Fatal("got nil postings list, expected non-nil") } - postingsItr := postingsList.Iterator() + postingsItr := postingsList.Iterator(true, true, true) if postingsItr == nil { t.Fatal("got nil iterator, expected non-nil") } @@ -211,7 +211,7 @@ func TestSingle(t *testing.T) { t.Fatal("got nil postings list, expected non-nil") } - postingsItr := postingsList.Iterator() + postingsItr := postingsList.Iterator(true, true, true) if postingsItr == nil { t.Fatal("got nil iterator, expected non-nil") } @@ -257,7 +257,7 @@ func TestSingle(t *testing.T) { t.Fatal("got nil postings list, expected non-nil") } - postingsItr = postingsList.Iterator() + postingsItr = postingsList.Iterator(true, true, true) if postingsItr == nil { t.Fatal("got nil iterator, expected non-nil") } @@ -325,7 +325,7 @@ func TestSingle(t *testing.T) { t.Fatal("got nil postings list, expected non-nil") } - postingsItr = postingsList.Iterator() + postingsItr = postingsList.Iterator(true, true, true) if postingsItr == nil { t.Fatal("got nil iterator, expected non-nil") } @@ -394,7 +394,7 @@ func TestSingle(t *testing.T) { t.Fatal("got nil postings list, expected non-nil") } - postingsItr = postingsList.Iterator() + postingsItr = postingsList.Iterator(true, true, true) if postingsItr == nil { t.Fatal("got nil iterator, expected non-nil") } @@ -638,7 +638,7 @@ func TestMultiple(t *testing.T) { t.Fatal("got nil postings list, expected non-nil") } - postingsItr := postingsList.Iterator() + postingsItr := postingsList.Iterator(true, true, true) if postingsItr == nil { t.Fatal("got nil iterator, expected non-nil") } @@ -677,7 +677,7 @@ func TestMultiple(t *testing.T) { t.Errorf("expected count from postings list to be 1, got %d", postingsListExcludingCount) } - postingsItrExcluding := postingsListExcluding.Iterator() + postingsItrExcluding := postingsListExcluding.Iterator(true, true, true) if postingsItr == nil { t.Fatal("got nil iterator, expected non-nil") } diff --git a/index/scorch/segment/segment.go b/index/scorch/segment/segment.go index 8eee5f75..adab7a01 100644 --- a/index/scorch/segment/segment.go +++ b/index/scorch/segment/segment.go @@ -55,7 +55,7 @@ type DictionaryIterator interface { } type PostingsList interface { - Iterator() PostingsIterator + Iterator(includeFreq, includeNorm, includeLocations bool) PostingsIterator Size() int diff --git a/index/scorch/segment/zap/merge.go b/index/scorch/segment/zap/merge.go index 167ebfa2..0d40d5f2 100644 --- a/index/scorch/segment/zap/merge.go +++ b/index/scorch/segment/zap/merge.go @@ -303,7 +303,7 @@ func persistMergedRest(segments []*SegmentBase, dropsIn []*roaring.Bitmap, return nil, 0, err2 } - postItr = postings.iterator(postItr) + postItr = postings.iterator(true, true, true, postItr) if fieldsSame { // can optimize by copying freq/norm/loc bytes directly diff --git a/index/scorch/segment/zap/merge_test.go b/index/scorch/segment/zap/merge_test.go index d931f6c2..2675bf83 100644 --- a/index/scorch/segment/zap/merge_test.go +++ b/index/scorch/segment/zap/merge_test.go @@ -332,8 +332,8 @@ func compareSegments(a, b *Segment) string { fieldName, next.Term, aplist.Count(), bplist.Count())) } - apitr := aplist.Iterator() - bpitr := bplist.Iterator() + apitr := aplist.Iterator(true, true, true) + bpitr := bplist.Iterator(true, true, true) if (apitr != nil) != (bpitr != nil) { rv = append(rv, fmt.Sprintf("field %s, term: %s, postingsList.Iterator() results different: %v %v", fieldName, next.Term, apitr, bpitr)) diff --git a/index/scorch/segment/zap/posting.go b/index/scorch/segment/zap/posting.go index cf1e1ab0..4092b685 100644 --- a/index/scorch/segment/zap/posting.go +++ b/index/scorch/segment/zap/posting.go @@ -131,11 +131,12 @@ func (p *PostingsList) OrInto(receiver *roaring.Bitmap) { } // Iterator returns an iterator for this postings list -func (p *PostingsList) Iterator() segment.PostingsIterator { - return p.iterator(nil) +func (p *PostingsList) Iterator(includeFreq, includeNorm, includeLocations bool) segment.PostingsIterator { + return p.iterator(includeFreq, includeNorm, includeLocations, nil) } -func (p *PostingsList) iterator(rv *PostingsIterator) *PostingsIterator { +func (p *PostingsList) iterator(includeFreq, includeNorm, includeLocations bool, + rv *PostingsIterator) *PostingsIterator { if rv == nil { rv = &PostingsIterator{} } else { @@ -495,10 +496,10 @@ func (i *PostingsIterator) Next() (segment.Posting, error) { if cap(i.nextLocs) >= int(rv.freq) { i.nextLocs = i.nextLocs[0:rv.freq] } else { - i.nextLocs = make([]Location, rv.freq, rv.freq * 2) + i.nextLocs = make([]Location, rv.freq, rv.freq*2) } if cap(i.nextSegmentLocs) < int(rv.freq) { - i.nextSegmentLocs = make([]segment.Location, rv.freq, rv.freq * 2) + i.nextSegmentLocs = make([]segment.Location, rv.freq, rv.freq*2) } rv.locs = i.nextSegmentLocs[0:rv.freq] for j := 0; j < int(rv.freq); j++ { diff --git a/index/scorch/segment/zap/segment_test.go b/index/scorch/segment/zap/segment_test.go index 50d5dbd7..9f0a4015 100644 --- a/index/scorch/segment/zap/segment_test.go +++ b/index/scorch/segment/zap/segment_test.go @@ -84,7 +84,7 @@ func TestOpen(t *testing.T) { t.Fatal("got nil postings list, expected non-nil") } - postingsItr := postingsList.Iterator() + postingsItr := postingsList.Iterator(true, true, true) if postingsItr == nil { t.Fatal("got nil iterator, expected non-nil") } @@ -130,7 +130,7 @@ func TestOpen(t *testing.T) { t.Fatal("got nil postings list, expected non-nil") } - postingsItr = postingsList.Iterator() + postingsItr = postingsList.Iterator(true, true, true) if postingsItr == nil { t.Fatal("got nil iterator, expected non-nil") } @@ -198,7 +198,7 @@ func TestOpen(t *testing.T) { t.Fatal("got nil postings list, expected non-nil") } - postingsItr = postingsList.Iterator() + postingsItr = postingsList.Iterator(true, true, true) if postingsItr == nil { t.Fatal("got nil iterator, expected non-nil") } @@ -267,7 +267,7 @@ func TestOpen(t *testing.T) { t.Fatal("got nil postings list, expected non-nil") } - postingsItr = postingsList.Iterator() + postingsItr = postingsList.Iterator(true, true, true) if postingsItr == nil { t.Fatal("got nil iterator, expected non-nil") } @@ -366,7 +366,7 @@ func TestOpenMulti(t *testing.T) { t.Fatal("got nil postings list, expected non-nil") } - postingsItr := postingsList.Iterator() + postingsItr := postingsList.Iterator(true, true, true) if postingsItr == nil { t.Fatal("got nil iterator, expected non-nil") } @@ -405,7 +405,7 @@ func TestOpenMulti(t *testing.T) { t.Errorf("expected count from postings list to be 1, got %d", postingsListExcludingCount) } - postingsItrExcluding := postingsListExcluding.Iterator() + postingsItrExcluding := postingsListExcluding.Iterator(true, true, true) if postingsItr == nil { t.Fatal("got nil iterator, expected non-nil") } @@ -466,7 +466,7 @@ func TestOpenMultiWithTwoChunks(t *testing.T) { t.Fatal("got nil postings list, expected non-nil") } - postingsItr := postingsList.Iterator() + postingsItr := postingsList.Iterator(true, true, true) if postingsItr == nil { t.Fatal("got nil iterator, expected non-nil") } @@ -500,7 +500,7 @@ func TestOpenMultiWithTwoChunks(t *testing.T) { t.Fatal("got nil postings list, expected non-nil") } - postingsItrExcluding := postingsListExcluding.Iterator() + postingsItrExcluding := postingsListExcluding.Iterator(true, true, true) if postingsItr == nil { t.Fatal("got nil iterator, expected non-nil") } diff --git a/index/scorch/snapshot_index.go b/index/scorch/snapshot_index.go index 6f4b0288..95343af7 100644 --- a/index/scorch/snapshot_index.go +++ b/index/scorch/snapshot_index.go @@ -394,7 +394,7 @@ func (i *IndexSnapshot) TermFieldReader(term []byte, field string, includeFreq, return nil, err } rv.postings[i] = pl - rv.iterators[i] = pl.Iterator() + rv.iterators[i] = pl.Iterator(includeFreq, includeNorm, includeTermVectors) } atomic.AddUint64(&i.parent.stats.TotTermSearchersStarted, uint64(1)) return rv, nil diff --git a/index/scorch/snapshot_segment.go b/index/scorch/snapshot_segment.go index edf52a6e..805e5664 100644 --- a/index/scorch/snapshot_segment.go +++ b/index/scorch/snapshot_segment.go @@ -165,7 +165,7 @@ func (cfd *cachedFieldDocs) prepareFields(field string, ss *SegmentSnapshot) { } cfd.size += uint64(size.SizeOfUint64) /* map key */ - postingsItr := postings.Iterator() + postingsItr := postings.Iterator(false, false, false) nextPosting, err2 := postingsItr.Next() for err2 == nil && nextPosting != nil { docNum := nextPosting.Number()