fix(history): now with same fuzzy tier, which command has higher score will be in higher order

This commit is contained in:
verse91
2026-04-19 12:25:55 +07:00
parent a5c27bdb94
commit b045aaf6af
+12 -4
View File
@@ -23,6 +23,7 @@ var (
type HistResult struct { type HistResult struct {
ID int ID int
Cmd string Cmd string
FuzzyScore int
} }
func init() { func init() {
@@ -139,13 +140,14 @@ func SearchHistory(query string) ([]HistResult, error) {
return results, nil return results, nil
} }
matches := searcherCache.Search(query, &fuzzyvn.SearchOptions{Limit: 100}) matches := searcherCache.SearchWithScores(query, &fuzzyvn.SearchOptions{Limit: 100})
var results []HistResult var results []HistResult
for _, m := range matches { for _, m := range matches {
results = append(results, HistResult{ results = append(results, HistResult{
ID: idMapCache[m], ID: idMapCache[m.Str],
Cmd: m, Cmd: m.Str,
FuzzyScore: m.Score,
}) })
} }
@@ -175,7 +177,13 @@ func SearchHistory(query string) ([]HistResult, error) {
if tI != tJ { if tI != tJ {
return tI < tJ // lower tier is better return tI < tJ // lower tier is better
} }
// if same tier, sort by ID descending (most recent first)
// If both are fuzzy matches (Tier 4), prioritize fuzzyvn score first!
if tI == 4 && results[i].FuzzyScore != results[j].FuzzyScore {
return results[i].FuzzyScore > results[j].FuzzyScore
}
// if same tier (and same fuzzy score), sort by ID descending (most recent first)
return results[i].ID > results[j].ID return results[i].ID > results[j].ID
}) })