From b69a84b33c88f716f15410681c9b483082404033 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Mon, 27 May 2024 15:02:59 +0200 Subject: levenshtein: Add some comments --- internal/levenshtein/levenshtein.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/levenshtein/levenshtein.go b/internal/levenshtein/levenshtein.go index 631161e..cf28607 100644 --- a/internal/levenshtein/levenshtein.go +++ b/internal/levenshtein/levenshtein.go @@ -34,12 +34,14 @@ func levenshtein(os, ot string) int { v0[i] = i } + // loop through every word in the first string for i := 0; i < n; i++ { v1[0] = i + 1 for j := 0; j < m; j++ { // calculate deletion cost, // insertion cost and - // substitution cost + // substitution cost to get from the string + // to the target dc := v0[j+1] + 1 ic := v1[j] + 1 var sc int @@ -71,6 +73,7 @@ func adjusted(substr, full string) int { } // KeywordPenalty is the penalty for matching on keywords instead of display names +// We have a penalty for matching on keywords because currently there are a lot of generic keywords const KeywordPenalty = 2 // DiscoveryScore computes the score of a discovery entry with the given search query -- cgit v1.2.3