diff --git a/merge.go b/merge.go index 560490b..683d920 100644 --- a/merge.go +++ b/merge.go @@ -304,6 +304,10 @@ func writePostings(postings *roaring.Bitmap, tfEncoder, locEncoder *chunkedIntCo use1HitEncoding func(uint64) (bool, uint64, uint64), w *CountHashWriter, bufMaxVarintLen64 []byte) ( offset uint64, err error) { + if postings == nil { + return 0, nil + } + termCardinality := postings.GetCardinality() if termCardinality <= 0 { return 0, nil diff --git a/section_inverted_text_index.go b/section_inverted_text_index.go index d19dc94..91a126e 100644 --- a/section_inverted_text_index.go +++ b/section_inverted_text_index.go @@ -412,7 +412,6 @@ func (i *invertedIndexOpaque) BytesRead() uint64 { func (i *invertedIndexOpaque) ResetBytesRead(uint64) {} func (io *invertedIndexOpaque) writeDicts(w *CountHashWriter) (dictOffsets []uint64, err error) { - if io.results == nil || len(io.results) == 0 { return nil, nil } @@ -462,7 +461,11 @@ func (io *invertedIndexOpaque) writeDicts(w *CountHashWriter) (dictOffsets []uin locs := io.Locs[pid] locOffset := 0 - chunkSize, err := getChunkSize(io.chunkMode, postingsBS.GetCardinality(), uint64(len(io.results))) + var cardinality uint64 + if postingsBS != nil { + cardinality = postingsBS.GetCardinality() + } + chunkSize, err := getChunkSize(io.chunkMode, cardinality, uint64(len(io.results))) if err != nil { return nil, err }