chore(pkg): replace fuzzyvn with fuzzy

This commit is contained in:
verse91
2026-05-10 00:18:14 +07:00
parent c6cfdd0695
commit e15e88e53d
5 changed files with 12 additions and 15 deletions
+3 -3
View File
@@ -11,7 +11,7 @@ import (
"os/exec" "os/exec"
"strings" "strings"
"github.com/versenilvis/fuzzyvn" "github.com/versenilvis/fuzzy"
"github.com/versenilvis/iris/commands/core" "github.com/versenilvis/iris/commands/core"
) )
@@ -64,8 +64,8 @@ func ZoxideGenerator() core.GeneratorFunc {
}) })
} }
} else if !strings.Contains(fullQuery, "/") { } else if !strings.Contains(fullQuery, "/") {
searcher := fuzzyvn.NewPlainSearcher(dirs) searcher := fuzzy.NewPlainSearcher(dirs)
matches := searcher.SearchWithScores(fullQuery, &fuzzyvn.SearchOptions{Limit: 10}) matches := searcher.SearchWithScores(fullQuery, &fuzzy.SearchOptions{Limit: 10})
for _, m := range matches { for _, m := range matches {
path := m.Str path := m.Str
display := strings.Replace(path, home, "~", 1) display := strings.Replace(path, home, "~", 1)
+2 -2
View File
@@ -6,7 +6,7 @@ The `history` module provides the Ctrl+R fuzzy search functionality by reading t
- **Zsh Extended Support**: Specifically parses the `: <timestamp>;<command>` format common in Zsh. - **Zsh Extended Support**: Specifically parses the `: <timestamp>;<command>` format common in Zsh.
- **Lazy Loading**: Doesn't read the disk until the user actually requests history. This keeps startup time instantaneous. - **Lazy Loading**: Doesn't read the disk until the user actually requests history. This keeps startup time instantaneous.
- **Fuzzy Search**: Integrated with the `fuzzyvn` search engine. - **Fuzzy Search**: Integrated with the `fuzzy` search engine.
- **Deduplication**: Automatically hides duplicate entries, showing only the most unique command variants. - **Deduplication**: Automatically hides duplicate entries, showing only the most unique command variants.
## Data Flow ## Data Flow
@@ -18,7 +18,7 @@ The `history` module provides the Ctrl+R fuzzy search functionality by reading t
- Reads `~/.zsh_history`. - Reads `~/.zsh_history`.
- Strips metadata using `;` delimiter. - Strips metadata using `;` delimiter.
- Populates a slice of commands. - Populates a slice of commands.
5. Search matches are sorted by the `fuzzyvn` engine. 5. Search matches are sorted by the `fuzzy` engine.
6. Suggestions are returned to the `overlay` for rendering. 6. Suggestions are returned to the `overlay` for rendering.
## Configuration ## Configuration
+2 -3
View File
@@ -6,7 +6,6 @@ require (
github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/lipgloss v1.1.0
github.com/creack/pty v1.1.24 github.com/creack/pty v1.1.24
github.com/spf13/cobra v1.10.2 github.com/spf13/cobra v1.10.2
github.com/versenilvis/fuzzyvn v0.3.0
golang.org/x/sys v0.42.0 golang.org/x/sys v0.42.0
golang.org/x/term v0.41.0 golang.org/x/term v0.41.0
) )
@@ -27,10 +26,10 @@ require (
github.com/muesli/termenv v0.16.0 // indirect github.com/muesli/termenv v0.16.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.10 // indirect github.com/spf13/pflag v1.0.10 // indirect
github.com/versenilvis/fuzzy v0.1.0-rc // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/text v0.32.0 // indirect
) )
// this is my personal project, I want to point to my local folder to debug and develop // this is my personal project, I want to point to my local folder to debug and develop
// the github version is the stable one // the github version is the stable one
replace github.com/versenilvis/fuzzyvn => ../fuzzyvn replace github.com/versenilvis/fuzzy => ../fuzzy
-2
View File
@@ -47,6 +47,4 @@ golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/term v0.41.0 h1:QCgPso/Q3RTJx2Th4bDLqML4W6iJiaXFq2/ftQF13YU= golang.org/x/term v0.41.0 h1:QCgPso/Q3RTJx2Th4bDLqML4W6iJiaXFq2/ftQF13YU=
golang.org/x/term v0.41.0/go.mod h1:3pfBgksrReYfZ5lvYM0kSO0LIkAl4Yl2bXOkKP7Ec2A= golang.org/x/term v0.41.0/go.mod h1:3pfBgksrReYfZ5lvYM0kSO0LIkAl4Yl2bXOkKP7Ec2A=
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+5 -5
View File
@@ -8,14 +8,14 @@ import (
"strings" "strings"
"sync" "sync"
"github.com/versenilvis/fuzzyvn" "github.com/versenilvis/fuzzy"
"github.com/versenilvis/iris/integration/shell" "github.com/versenilvis/iris/integration/shell"
) )
var ( var (
historyCache []string historyCache []string
idMapCache map[string]int idMapCache map[string]int
searcherCache *fuzzyvn.Searcher searcherCache *fuzzy.Searcher
mu sync.Mutex mu sync.Mutex
lastModTime int64 lastModTime int64
) )
@@ -120,7 +120,7 @@ func SearchHistory(query string) ([]HistResult, error) {
} }
} }
searcherCache = fuzzyvn.NewPlainSearcher(historyCache) searcherCache = fuzzy.NewPlainSearcher(historyCache)
} }
if query == "" { if query == "" {
@@ -140,7 +140,7 @@ func SearchHistory(query string) ([]HistResult, error) {
return results, nil return results, nil
} }
matches := searcherCache.SearchWithScores(query, &fuzzyvn.SearchOptions{Limit: 100}) matches := searcherCache.SearchWithScores(query, &fuzzy.SearchOptions{Limit: 100})
var results []HistResult var results []HistResult
for _, m := range matches { for _, m := range matches {
@@ -178,7 +178,7 @@ func SearchHistory(query string) ([]HistResult, error) {
return tI < tJ // lower tier is better return tI < tJ // lower tier is better
} }
// If both are fuzzy matches (Tier 4), prioritize fuzzyvn score first! // If both are fuzzy matches (Tier 4), prioritize fuzzy score first!
if tI == 4 && results[i].FuzzyScore != results[j].FuzzyScore { if tI == 4 && results[i].FuzzyScore != results[j].FuzzyScore {
return results[i].FuzzyScore > results[j].FuzzyScore return results[i].FuzzyScore > results[j].FuzzyScore
} }