summaryrefslogtreecommitdiff
path: root/core/search
diff options
context:
space:
mode:
authoralex <[email protected]>2026-10-10 22:49:19 +0200
committeralex <[email protected]>2026-10-10 22:49:19 +0200
commit251bb0cf9e58caa0d22066681d93ea09639f53eb (patch)
tree0529e74c94942508b77bea7df3cc8dc2e02b3d58 /core/search
parentb2e05a1d41540586cbaa7c8ee532393501601154 (diff)
downloadsearch-engine-251bb0cf9e58caa0d22066681d93ea09639f53eb.tar.xz
search-engine-251bb0cf9e58caa0d22066681d93ea09639f53eb.zip
unknownHEADmain
Diffstat (limited to 'core/search')
-rw-r--r--core/search/search.go11
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]})
}
}