Improve search relevance and artist transliteration
ci / api / api (push) Successful in 56s
ci / db / db (push) Successful in 1m13s

This commit is contained in:
mrleo1nid committed 2026-10-30 12:09:24 +03:00
1 parent db4548b115
commit 82f3eed9a0
10 files changed
+212 -12

No files matched your search

+30
View File
@@ -6,6 +6,36 @@ import (
"unicode"
)
// Established spellings cannot always be derived letter by letter. Keep these
// as whole-word alternatives, retaining the mechanical transliteration too.
var pronunciationWords = map[string]string{"boulevard": "бульвар"}
func TranslitVariants(s string) []string {
out := []string{}
if mechanical := Translit(s); mechanical != "" {
out = append(out, mechanical)
}
words := strings.Fields(strings.ToLower(s))
changed := false
for i, word := range words {
if spoken, ok := pronunciationWords[word]; ok {
words[i], changed = spoken, true
} else if translated := Translit(word); translated != "" {
words[i] = translated
}
}
if changed {
out = append(out, strings.Join(words, " "))
}
return out
}
func searchKey(s string) string {
return strings.Join(strings.FieldsFunc(strings.ToLower(s), func(r rune) bool {
return !unicode.IsLetter(r) && !unicode.IsDigit(r)
}), " ")
}
// Кириллица → латиница (упрощённая ГОСТ-подобная схема: «Кино» → «kino», «Щедрин» → «shchedrin»).
var cyrToLat = map[rune]string{
'а': "a", 'б': "b", 'в': "v", 'г': "g", 'д': "d", 'е': "e", 'ё': "e", 'ж': "zh", 'з': "z", 'и': "i",