diff options
| author | alex <[email protected]> | 2026-07-28 14:22:32 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-28 14:22:32 +0200 |
| commit | 152c73d8205a252d4311595ffba562110334fd0f (patch) | |
| tree | ac53d51b85d1148bebf66ecdfe8320a3e99ed155 /scoring/idf.go | |
| parent | 49a21882354c1a92fcb9c5b555c0331ab83c2e69 (diff) | |
| download | search-engine-152c73d8205a252d4311595ffba562110334fd0f.tar.xz search-engine-152c73d8205a252d4311595ffba562110334fd0f.zip | |
begin work on better searching algorithms, created logic for tf-idf
Diffstat (limited to 'scoring/idf.go')
| -rw-r--r-- | scoring/idf.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/scoring/idf.go b/scoring/idf.go new file mode 100644 index 0000000..6d96089 --- /dev/null +++ b/scoring/idf.go @@ -0,0 +1,17 @@ +package scoring + +import ( + "math" + "searchEngine/index" +) + +func CalculateIDF(totalDocs int, docFrequency int) float64 { + if docFrequency == 0 { + return 0.0 + } + return math.Log10(float64(totalDocs) / float64(docFrequency)) +} +func ScoreTFIDF(p index.Posting, idf float64) float64 { + + return float64(p.Count) * idf +} |
