Skip to content

Commit

Permalink
use ctx in term srch
Browse files Browse the repository at this point in the history
  • Loading branch information
metonymic-smokey authored and Thejas-bhat committed Dec 6, 2024
1 parent dd4589e commit 0abb3e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion search/searcher/search_disjunction.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func optimizeCompositeSearcher(ctx context.Context, optimizationKind string,
return nil, nil
}

return newTermSearcherFromReader(indexReader, tfr,
return newTermSearcherFromReader(ctx, indexReader, tfr,
[]byte(optimizationKind), "*", 1.0, options)
}

Expand Down
21 changes: 14 additions & 7 deletions search/searcher/search_term.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package searcher

import (
"context"
"fmt"
"reflect"

"github.com/blevesearch/bleve/v2/search"
Expand Down Expand Up @@ -51,17 +52,23 @@ func NewTermSearcherBytes(ctx context.Context, indexReader index.IndexReader, te
if err != nil {
return nil, err
}
return newTermSearcherFromReader(indexReader, reader, term, field, boost, options)
return newTermSearcherFromReader(ctx, indexReader, reader, term, field, boost, options)
}

func newTermSearcherFromReader(indexReader index.IndexReader, reader index.TermFieldReader,
func newTermSearcherFromReader(ctx context.Context, indexReader index.IndexReader, reader index.TermFieldReader,
term []byte, field string, boost float64, options search.SearcherOptions) (*TermSearcher, error) {
// TODO Instead of passing count from reader here, do it using the presearch phase stats.
count, err := indexReader.DocCount()
if err != nil {
_ = reader.Close()
return nil, err
count, ok := ctx.Value(search.BM25PreSearchDataKey).(uint64)
if !ok {
var err error
count, err = indexReader.DocCount()
if err != nil {
_ = reader.Close()
return nil, err
}
} else {
fmt.Printf("fetched from ctx \n")
}

scorer := scorer.NewTermQueryScorer(term, field, boost, count, reader.Count(), options)
return &TermSearcher{
indexReader: indexReader,
Expand Down

0 comments on commit 0abb3e6

Please sign in to comment.