func (o *OptimizeTFRConjunctionUnadorned) Finish() (rv index.Optimized, err error) {
	if len(o.tfrs) <= 1 {
		return nil, nil
	}
	oTFR := o.snapshot.unadornedTermFieldReader(
		OptimizeTFRConjunctionUnadornedTerm, OptimizeTFRConjunctionUnadornedField)
	var actualBMs []*roaring.Bitmap  
OUTER:
	for i := range o.snapshot.segment {
		actualBMs = actualBMs[:0]
		var docNum1HitLast uint64
		var docNum1HitLastOk bool
		for _, tfr := range o.tfrs {
			if _, ok := tfr.iterators[i].(*emptyPostingsIterator); ok {
				oTFR.iterators[i] = anEmptyPostingsIterator
				continue OUTER
			}
			itr, ok := tfr.iterators[i].(segment.OptimizablePostingsIterator)
			if !ok {
				return nil, nil
			}
			docNum1Hit, ok := itr.DocNum1Hit()
			if ok {
				if docNum1HitLastOk && docNum1HitLast != docNum1Hit {
					oTFR.iterators[i] = anEmptyPostingsIterator
					continue OUTER
				}
				docNum1HitLast = docNum1Hit
				docNum1HitLastOk = true
				continue
			}
			if itr.ActualBitmap() == nil {
				oTFR.iterators[i] = anEmptyPostingsIterator
				continue OUTER
			}
			actualBMs = append(actualBMs, itr.ActualBitmap())
		}
		if docNum1HitLastOk {
			for _, bm := range actualBMs {
				if !bm.Contains(uint32(docNum1HitLast)) {
					oTFR.iterators[i] = anEmptyPostingsIterator
					continue OUTER
				}
			}
			oTFR.iterators[i] = newUnadornedPostingsIteratorFrom1Hit(docNum1HitLast)
			continue OUTER
		}
		if len(actualBMs) == 0 {
			oTFR.iterators[i] = anEmptyPostingsIterator
			continue OUTER
		}
		if len(actualBMs) == 1 {
			oTFR.iterators[i] = newUnadornedPostingsIteratorFromBitmap(actualBMs[0])
			continue OUTER
		}
		bm := roaring.And(actualBMs[0], actualBMs[1])
		for _, actualBM := range actualBMs[2:] {
			bm.And(actualBM)
		}
		oTFR.iterators[i] = newUnadornedPostingsIteratorFromBitmap(bm)
	}
	atomic.AddUint64(&o.snapshot.parent.stats.TotTermSearchersStarted, uint64(1))
	return oTFR, nil
}
Finish of an unadorned conjunction optimization will compute a
termFieldReader with an "actual" bitmap that represents the
constituent bitmaps AND'ed together.  This termFieldReader cannot
provide any freq-norm or termVector associated information.
package scorch
import (
	"fmt"
	"github.com/RoaringBitmap/roaring"
	index "github.com/blevesearch/bleve_index_api"
	segment "github.com/blevesearch/scorch_segment_api/v2"
	"sync/atomic"
)
var OptimizeConjunction = true
var OptimizeConjunctionUnadorned = true
var OptimizeDisjunctionUnadorned = true
func (s *IndexSnapshotTermFieldReader) Optimize(kind string,
	octx index.OptimizableContext) (index.OptimizableContext, error) {
	if OptimizeConjunction && kind == "conjunction" {
		return s.optimizeConjunction(octx)
	}
	if OptimizeConjunctionUnadorned && kind == "conjunction:unadorned" {
		return s.optimizeConjunctionUnadorned(octx)
	}
	if OptimizeDisjunctionUnadorned && kind == "disjunction:unadorned" {
		return s.optimizeDisjunctionUnadorned(octx)
	}
	return nil, nil
}
var OptimizeDisjunctionUnadornedMinChildCardinality = uint64(256)
func (s *IndexSnapshotTermFieldReader) optimizeConjunction(
	octx index.OptimizableContext) (index.OptimizableContext, error) {
	if octx == nil {
		octx = &OptimizeTFRConjunction{snapshot: s.snapshot}
	}
	o, ok := octx.(*OptimizeTFRConjunction)
	if !ok {
		return octx, nil
	}
	if o.snapshot != s.snapshot {
		return nil, fmt.Errorf("tried to optimize conjunction across different snapshots")
	}
	o.tfrs = append(o.tfrs, s)
	return o, nil
}
type OptimizeTFRConjunction struct {
	snapshot *IndexSnapshot
	tfrs []*IndexSnapshotTermFieldReader
}
func (o *OptimizeTFRConjunction) Finish() (index.Optimized, error) {
	if len(o.tfrs) <= 1 {
		return nil, nil
	}
	for i := range o.snapshot.segment {
		itr0, ok := o.tfrs[0].iterators[i].(segment.OptimizablePostingsIterator)
		if !ok || itr0.ActualBitmap() == nil {
			continue
		}
		itr1, ok := o.tfrs[1].iterators[i].(segment.OptimizablePostingsIterator)
		if !ok || itr1.ActualBitmap() == nil {
			continue
		}
		bm := roaring.And(itr0.ActualBitmap(), itr1.ActualBitmap())
		for _, tfr := range o.tfrs[2:] {
			itr, ok := tfr.iterators[i].(segment.OptimizablePostingsIterator)
			if !ok || itr.ActualBitmap() == nil {
				continue
			}
			bm.And(itr.ActualBitmap())
		}
		for _, tfr := range o.tfrs {
			itr, ok := tfr.iterators[i].(segment.OptimizablePostingsIterator)
			if ok && itr.ActualBitmap() != nil {
				itr.ReplaceActual(bm)
			}
		}
	}
	return nil, nil
}
func (s *IndexSnapshotTermFieldReader) optimizeConjunctionUnadorned(
	octx index.OptimizableContext) (index.OptimizableContext, error) {
	if octx == nil {
		octx = &OptimizeTFRConjunctionUnadorned{snapshot: s.snapshot}
	}
	o, ok := octx.(*OptimizeTFRConjunctionUnadorned)
	if !ok {
		return nil, nil
	}
	if o.snapshot != s.snapshot {
		return nil, fmt.Errorf("tried to optimize unadorned conjunction across different snapshots")
	}
	o.tfrs = append(o.tfrs, s)
	return o, nil
}
type OptimizeTFRConjunctionUnadorned struct {
	snapshot *IndexSnapshot
	tfrs []*IndexSnapshotTermFieldReader
}
var OptimizeTFRConjunctionUnadornedTerm = []byte("<conjunction:unadorned>")
var OptimizeTFRConjunctionUnadornedField = "*"