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/scoring/BM25.go | |
| parent | b2e05a1d41540586cbaa7c8ee532393501601154 (diff) | |
| download | search-engine-251bb0cf9e58caa0d22066681d93ea09639f53eb.tar.xz search-engine-251bb0cf9e58caa0d22066681d93ea09639f53eb.zip | |
Diffstat (limited to 'core/scoring/BM25.go')
| -rw-r--r-- | core/scoring/BM25.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/core/scoring/BM25.go b/core/scoring/BM25.go new file mode 100644 index 0000000..122c7f3 --- /dev/null +++ b/core/scoring/BM25.go @@ -0,0 +1,20 @@ +package scoring + +import "searchEngine/core/index" + +var k1 float64 = 1.2 +var b float64 = 0.75 + +func ScoreBM25(p index.Posting, idf float64, docLen int, avgDocLen float64) float64 { + tf := float64(len(p.BodyPositions)) + + if tf == 0 { + return 0.0 + } + + numerator := idf * (tf * (k1 + 1)) + + denominator := tf + k1*(1.0-b+b*(float64(docLen)/avgDocLen)) + + return numerator / denominator +} |
