fix(history): ranking (#46)

- I removed scoring system in history and it now only works in spec mode
- Also fix the AI suggestion placed in 3rd place instead of the first in
history mode ad7e2886950dc4e58b1cfac6fe15e4bb7a298865
- Clean up suggestions code
This commit is contained in:
VERSE
2026-07-28 10:47:56 +07:00
committed by GitHub
parent 5a05dc7553
commit 93061c89ca
2 changed files with 103 additions and 57 deletions
+44 -1
View File
@@ -225,7 +225,50 @@ func SearchHistory(query string, aliases map[string]string) ([]HistResult, error
}
}
matches := searcherCache.SearchWithScores(q, &fuzzy.SearchOptions{Limit: 200})
// extract pure prefix matches based strictly on recency order (historyCache is newest-first)
strictMatches := 0
for _, cmd := range historyCache {
if seenCmds[cmd] {
continue
}
fields := strings.Fields(cmd)
firstWordLow := ""
if len(fields) > 0 {
firstWordLow = strings.ToLower(fields[0])
}
if queryFirstWord != "" {
if firstWordLow != queryFirstWord {
continue
}
if subcmdFilter && querySecondWord != "" {
if len(fields) < 2 {
continue
}
secondWordLow := strings.ToLower(fields[1])
if !strings.HasPrefix(secondWordLow, querySecondWord) {
continue
}
}
} else {
if !strings.HasPrefix(firstWordLow, qLow) {
continue
}
}
seenCmds[cmd] = true
results = append(results, HistResult{
ID: idMapCache[cmd],
Cmd: cmd,
FuzzyScore: 10000,
})
strictMatches++
if strictMatches >= 200 {
break
}
}
matches := searcherCache.SearchWithScores(q, &fuzzy.SearchOptions{Limit: 1000})
for _, m := range matches {
if seenCmds[m.Str] {
continue