Browse Source

optimization Finish() may return optimized resources

This is a plumbing level API change, where an optimization is now
allowed to return alternative resources in its Finish()
implementation.

For example, this might be useful in future commits, where scorch
codepaths might return an alternate index.TermFieldReader instance for
optimizing non-scoring disjunctions.
Steve Yen 5 months ago
parent
commit
c15bb65ae6
3 changed files with 13 additions and 5 deletions
  1. 9 1
      index/index.go
  2. 3 3
      index/scorch/optimize.go
  3. 1 1
      search/searcher/search_conjunction.go

+ 9 - 1
index/index.go

@@ -341,11 +341,19 @@ type Optimizable interface {
 	Optimize(kind string, octx OptimizableContext) (OptimizableContext, error)
 }
 
+// Represents a result of optimization -- see the Finish() method.
+type Optimized interface{}
+
 type OptimizableContext interface {
 	// Once all the optimzable resources have been provided the same
 	// OptimizableContext instance, the optimization preparations are
 	// finished or completed via the Finish() method.
-	Finish() error
+	//
+	// Depending on the optimization being performed, the Finish()
+	// method might return a non-nil Optimized instance.  For example,
+	// the Optimized instance might represent an optimized
+	// TermFieldReader instance.
+	Finish() (Optimized, error)
 }
 
 type DocValueReader interface {

+ 3 - 3
index/scorch/optimize.go

@@ -53,9 +53,9 @@ type OptimizeTFRConjunction struct {
 	tfrs []*IndexSnapshotTermFieldReader
 }
 
-func (o *OptimizeTFRConjunction) Finish() error {
+func (o *OptimizeTFRConjunction) Finish() (index.Optimized, error) {
 	if len(o.tfrs) <= 1 {
-		return nil
+		return nil, nil
 	}
 
 	for i := range o.snapshot.segment {
@@ -89,5 +89,5 @@ func (o *OptimizeTFRConjunction) Finish() error {
 		}
 	}
 
-	return nil
+	return nil, nil
 }

+ 1 - 1
search/searcher/search_conjunction.go

@@ -77,7 +77,7 @@ func NewConjunctionSearcher(indexReader index.IndexReader, qsearchers []search.S
 		}
 
 		if octx != nil {
-			err := octx.Finish()
+			_, err := octx.Finish()
 			if err != nil {
 				return nil, err
 			}