Alphabetic sorting now ignores cases.

Slightly changed the algorithm to prefer letters closer to the start of
the word.
This commit is contained in:
Avahe Kellenberger 2019-08-13 17:12:17 -04:00 committed by Marcel Schramm
parent d2c8529b91
commit 86abfda8f0
1 changed files with 2 additions and 2 deletions

View File

@ -29,7 +29,7 @@ func SortSearchResults(results map[string]float64) []SearchResult {
sort.Slice(arr, func(i, j int) bool {
if arr[i].Value == arr[j].Value {
return strings.Compare(arr[i].Key, arr[j].Key) < 0
return strings.Compare(strings.ToLower(arr[i].Key), strings.ToLower(arr[j].Key)) < 0
}
return arr[i].Value > arr[j].Value
})
@ -68,7 +68,7 @@ func Score(needle, haystack string) float64 {
// Letter was consecutive
score += 8
} else {
score++
score += 1 - (0.1 * float64(letterIndex))
// Move haystackIndex up to the next found letter.
haystackIndex = letterIndex
}