summaryrefslogtreecommitdiff
path: root/core/scoring
diff options
context:
space:
mode:
authoralex <[email protected]>2026-07-29 00:56:57 +0200
committeralex <[email protected]>2026-07-29 00:56:57 +0200
commitb2e05a1d41540586cbaa7c8ee532393501601154 (patch)
tree2e39c75f30f95f5b308769c1def673fb4ac0538b /core/scoring
parent95ccea8d0244e515947c335ace620838f01be60a (diff)
downloadsearch-engine-b2e05a1d41540586cbaa7c8ee532393501601154.tar.xz
search-engine-b2e05a1d41540586cbaa7c8ee532393501601154.zip
added proximity based scoringHEADmain
Diffstat (limited to 'core/scoring')
-rw-r--r--core/scoring/proximity.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/core/scoring/proximity.go b/core/scoring/proximity.go
new file mode 100644
index 0000000..f765aa7
--- /dev/null
+++ b/core/scoring/proximity.go
@@ -0,0 +1,31 @@
+package scoring
+
+import "math"
+
+func CalculateProximity(pos1, pos2 []int) float64 {
+ var score float64
+ i, j := 0, 0
+
+ for i < len(pos1) && j < len(pos2) {
+ p1 := pos1[i]
+ p2 := pos2[j]
+
+ dist := math.Abs(float64(p1 - p2))
+
+ if dist == 1 {
+ score += 15.0
+ } else if dist <= 5 {
+ score += 5.0
+ } else if dist <= 15 {
+ score += 1.0
+ }
+
+ if p1 < p2 {
+ i++
+ } else {
+ j++
+ }
+ }
+
+ return score
+}