@@ -17,11 +17,11 @@ package lib
1717
1818import (
1919 "context"
20- "strings"
2120
2221 "github.com/arduino/arduino-cli/arduino"
2322 "github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
2423 "github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
24+ "github.com/arduino/arduino-cli/arduino/utils"
2525 "github.com/arduino/arduino-cli/commands"
2626 rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2727 semver "go.bug.st/relaxed-semver"
@@ -38,40 +38,23 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchRequest) (*rpc.Lib
3838
3939func searchLibrary (req * rpc.LibrarySearchRequest , lm * librariesmanager.LibrariesManager ) * rpc.LibrarySearchResponse {
4040 res := []* rpc.SearchedLibrary {}
41- status := rpc .LibrarySearchStatus_LIBRARY_SEARCH_STATUS_SUCCESS
42-
43- // Split on anything but 0-9, a-z or :
4441 queryTerms := rpc .SearchTermsFromQueryString (req .GetQuery ())
4542
4643 for _ , lib := range lm .Index .Libraries {
47- matchTerm := func (x string ) bool {
48- if strings .Contains (strings .ToLower (lib .Name ), x ) ||
49- strings .Contains (strings .ToLower (lib .Latest .Paragraph ), x ) ||
50- strings .Contains (strings .ToLower (lib .Latest .Sentence ), x ) ||
51- strings .Contains (strings .ToLower (lib .Latest .Author ), x ) {
52- return true
53- }
54- for _ , include := range lib .Latest .ProvidesIncludes {
55- if strings .Contains (strings .ToLower (include ), x ) {
56- return true
57- }
58- }
59- return false
60- }
61- match := func () bool {
62- for _ , term := range queryTerms {
63- if ! matchTerm (term ) {
64- return false
65- }
66- }
67- return true
44+ toTest := lib .Name + " " +
45+ lib .Latest .Paragraph + " " +
46+ lib .Latest .Sentence + " " +
47+ lib .Latest .Author + " "
48+ for _ , include := range lib .Latest .ProvidesIncludes {
49+ toTest += include + " "
6850 }
69- if match () {
51+
52+ if utils .Match (toTest , queryTerms ) {
7053 res = append (res , indexLibraryToRPCSearchLibrary (lib ))
7154 }
7255 }
7356
74- return & rpc.LibrarySearchResponse {Libraries : res , Status : status }
57+ return & rpc.LibrarySearchResponse {Libraries : res , Status : rpc . LibrarySearchStatus_LIBRARY_SEARCH_STATUS_SUCCESS }
7558}
7659
7760// indexLibraryToRPCSearchLibrary converts a librariindex.Library to rpc.SearchLibrary
0 commit comments