diff options
| author | alex <[email protected]> | 2026-10-10 22:49:19 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-10-10 22:49:19 +0200 |
| commit | 251bb0cf9e58caa0d22066681d93ea09639f53eb (patch) | |
| tree | 0529e74c94942508b77bea7df3cc8dc2e02b3d58 /core/search | |
| parent | b2e05a1d41540586cbaa7c8ee532393501601154 (diff) | |
| download | search-engine-251bb0cf9e58caa0d22066681d93ea09639f53eb.tar.xz search-engine-251bb0cf9e58caa0d22066681d93ea09639f53eb.zip | |
Diffstat (limited to 'core/search')
| -rw-r--r-- | core/search/search.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/core/search/search.go b/core/search/search.go index cf1054b..af35cae 100644 --- a/core/search/search.go +++ b/core/search/search.go @@ -39,7 +39,7 @@ func Search(idx *index.InvertedIndex, query string) []string { for _, token := range tokenizedQuery { postings, exists := idx.Data[token] if !exists { - return nil + continue } docFrequency := len(postings) @@ -47,16 +47,21 @@ func Search(idx *index.InvertedIndex, query string) []string { for _, p := range postings { docMatchCounts[p.DocId]++ - termScore := scoring.ScoreTFIDF(p, idf) + termScore := scoring.ScoreBM25(p, idf, len(p.BodyPositions), idx.AvgDocLen) + if len(p.TitlePositions) > 0 { + termScore += 5.0 + } scores[p.DocId] += termScore docPostings[p.DocId] = append(docPostings[p.DocId], p) } } + requiredMatches := max(int(float64(len(uniqueTokens))*1.0), 1) + var results []Result for docID, count := range docMatchCounts { - if count == len(uniqueTokens) { + if count >= requiredMatches { results = append(results, Result{DocID: docID, Score: scores[docID]}) } } |
