Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Thejas-bhat committed Dec 12, 2024
1 parent 149196c commit 45efde1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
6 changes: 4 additions & 2 deletions index_alias_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package bleve

import (
"context"
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -657,8 +658,8 @@ func requestSatisfiedByPreSearch(req *SearchRequest, flags *preSearchFlags) bool
func constructBM25PreSearchData(rv map[string]map[string]interface{}, sr *SearchResult, indexes []Index) map[string]map[string]interface{} {
for _, index := range indexes {
rv[index.Name()][search.BM25PreSearchDataKey] = map[string]interface{}{
"docCount": sr.docCount,
"fieldCardinality": sr.fieldCardinality,
"docCount": sr.DocCount,
"fieldCardinality": sr.FieldCardinality,
}
}
return rv
Expand Down Expand Up @@ -854,6 +855,7 @@ func MultiSearch(ctx context.Context, req *SearchRequest, preSearchData map[stri
var payload map[string]interface{}
if preSearchData != nil {
payload = preSearchData[in.Name()]
fmt.Println("the payload", payload)
}
go searchChildIndex(in, createChildSearchRequest(req, payload))
}
Expand Down
9 changes: 6 additions & 3 deletions index_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,10 @@ func (i *indexImpl) preSearch(ctx context.Context, req *SearchRequest, reader in
}

fs := make(query.FieldSet)
fs = query.ExtractFields(req.Query, i.m, fs)
fs, err = query.ExtractFields(req.Query, i.m, fs)
if err != nil {
return nil, err
}

for field := range fs {
dict, err := reader.FieldDict(field)
Expand All @@ -478,8 +481,8 @@ func (i *indexImpl) preSearch(ctx context.Context, req *SearchRequest, reader in
Successful: 1,
},
Hits: knnHits,
docCount: count,
fieldCardinality: fieldCardinality,
DocCount: count,
FieldCardinality: fieldCardinality,
}, nil
}

Expand Down
8 changes: 4 additions & 4 deletions pre_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ func newBM25PreSearchResultProcessor() *bm25PreSearchResultProcessor {

// TODO How will this work for queries other than term queries?
func (b *bm25PreSearchResultProcessor) add(sr *SearchResult, indexName string) {
b.docCount += (sr.docCount)
for field, cardinality := range sr.fieldCardinality {
b.docCount += (sr.DocCount)
for field, cardinality := range sr.FieldCardinality {
b.fieldCardinality[field] += cardinality
}
}

func (b *bm25PreSearchResultProcessor) finalize(sr *SearchResult) {
sr.docCount = b.docCount
sr.fieldCardinality = b.fieldCardinality
sr.DocCount = b.docCount
sr.FieldCardinality = b.fieldCardinality
}

// -----------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ type SearchResult struct {
Facets search.FacetResults `json:"facets"`

// The following fields are applicable to BM25 preSearch
docCount uint64
fieldCardinality map[string]int // search_field -> cardinality
DocCount uint64
FieldCardinality map[string]int // search_field -> cardinality
}

func (sr *SearchResult) Size() int {
Expand Down
14 changes: 3 additions & 11 deletions search/searcher/search_term.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package searcher
import (
"context"
"fmt"
"math"
"reflect"

"github.com/blevesearch/bleve/v2/search"
Expand Down Expand Up @@ -65,10 +66,6 @@ func tfTDFScoreMetrics(indexReader index.IndexReader) (uint64, float64, error) {
}
fieldCardinality := 0

fmt.Println("----------tf-idf stats--------")
fmt.Println("docCount: ", count)
fmt.Println("fieldCardinality: ", fieldCardinality)

if count == 0 && fieldCardinality == 0 {
return 0, 0, nil
}
Expand Down Expand Up @@ -100,22 +97,17 @@ func bm25ScoreMetrics(ctx context.Context, field string,
if !ok {
return 0, 0, fmt.Errorf("field stat for bm25 not present %s", field)
}

fmt.Println("----------bm25 stats--------")
fmt.Println("docCount: ", count)
fmt.Println("fieldCardinality: ", fieldCardinality)
fmt.Println("avgDocLength: ", fieldCardinality/int(count))
}

fmt.Println("----------bm25 stats--------")
fmt.Println("docCount: ", count)
fmt.Println("fieldCardinality: ", fieldCardinality)
fmt.Println("avgDocLength: ", fieldCardinality/int(count))
fmt.Println("avgDocLength: ", math.Ceil(float64(fieldCardinality)/float64(count)))

if count == 0 && fieldCardinality == 0 {
return 0, 0, nil
}
return count, float64(fieldCardinality / int(count)), nil
return count, math.Ceil(float64(fieldCardinality) / float64(count)), nil
}

func newTermSearcherFromReader(ctx context.Context, indexReader index.IndexReader,
Expand Down

0 comments on commit 45efde1

Please sign in to comment.