Skip to content

Commit 83534f8

Browse files
authored
feat(gallery): add fuzzy search (#6481)
chore(model gallery): add fuzzy search Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 75eaf8c commit 83534f8

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

core/gallery/gallery.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import (
66
"path/filepath"
77
"strings"
88

9+
"github.com/lithammer/fuzzysearch/fuzzy"
910
"github.com/mudler/LocalAI/core/config"
1011
"github.com/mudler/LocalAI/pkg/downloader"
1112
"github.com/mudler/LocalAI/pkg/system"
1213
"github.com/rs/zerolog/log"
14+
1315
"gopkg.in/yaml.v2"
1416
)
1517

@@ -58,9 +60,9 @@ func (gm GalleryElements[T]) Search(term string) GalleryElements[T] {
5860
var filteredModels GalleryElements[T]
5961

6062
for _, m := range gm {
61-
if strings.Contains(m.GetName(), term) ||
62-
strings.Contains(m.GetDescription(), term) ||
63-
strings.Contains(m.GetGallery().Name, term) ||
63+
if fuzzy.Match(term, m.GetName()) ||
64+
fuzzy.Match(term, m.GetDescription()) ||
65+
fuzzy.Match(term, m.GetGallery().Name) ||
6466
strings.Contains(strings.Join(m.GetTags(), ","), term) {
6567
filteredModels = append(filteredModels, m)
6668
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ require (
9999
github.com/json-iterator/go v1.1.12 // indirect
100100
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 // indirect
101101
github.com/libp2p/go-yamux/v5 v5.0.1 // indirect
102+
github.com/lithammer/fuzzysearch v1.1.8 // indirect
102103
github.com/magiconair/properties v1.8.10 // indirect
103104
github.com/moby/docker-image-spec v1.3.1 // indirect
104105
github.com/moby/go-archive v0.1.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ github.com/libp2p/go-yamux/v5 v5.0.1 h1:f0WoX/bEF2E8SbE4c/k1Mo+/9z0O4oC/hWEA+nfY
431431
github.com/libp2p/go-yamux/v5 v5.0.1/go.mod h1:en+3cdX51U0ZslwRdRLrvQsdayFt3TSUKvBGErzpWbU=
432432
github.com/libp2p/zeroconf/v2 v2.2.0 h1:Cup06Jv6u81HLhIj1KasuNM/RHHrJ8T7wOTS4+Tv53Q=
433433
github.com/libp2p/zeroconf/v2 v2.2.0/go.mod h1:fuJqLnUwZTshS3U/bMRJ3+ow/v9oid1n0DmyYyNO1Xs=
434+
github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4=
435+
github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4=
434436
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
435437
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
436438
github.com/lufia/plan9stats v0.0.0-20240819163618-b1d8f4d146e7 h1:5RK988zAqB3/AN3opGfRpoQgAVqr6/A5+qRTi67VUZY=

0 commit comments

Comments
 (0)