File tree Expand file tree Collapse file tree 3 files changed +8
-3
lines changed Expand file tree Collapse file tree 3 files changed +8
-3
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -431,6 +431,8 @@ github.com/libp2p/go-yamux/v5 v5.0.1 h1:f0WoX/bEF2E8SbE4c/k1Mo+/9z0O4oC/hWEA+nfY
431431github.com/libp2p/go-yamux/v5 v5.0.1 /go.mod h1:en+3cdX51U0ZslwRdRLrvQsdayFt3TSUKvBGErzpWbU =
432432github.com/libp2p/zeroconf/v2 v2.2.0 h1:Cup06Jv6u81HLhIj1KasuNM/RHHrJ8T7wOTS4+Tv53Q =
433433github.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 =
434436github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY =
435437github.com/lucasb-eyer/go-colorful v1.2.0 /go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0 =
436438github.com/lufia/plan9stats v0.0.0-20240819163618-b1d8f4d146e7 h1:5RK988zAqB3/AN3opGfRpoQgAVqr6/A5+qRTi67VUZY =
You can’t perform that action at this time.
0 commit comments