@@ -17,11 +17,11 @@ package lib
17
17
18
18
import (
19
19
"context"
20
- "strings"
21
20
22
21
"github.com/arduino/arduino-cli/arduino"
23
22
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
24
23
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
24
+ "github.com/arduino/arduino-cli/arduino/utils"
25
25
"github.com/arduino/arduino-cli/commands"
26
26
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
27
27
semver "go.bug.st/relaxed-semver"
@@ -38,40 +38,23 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchRequest) (*rpc.Lib
38
38
39
39
func searchLibrary (req * rpc.LibrarySearchRequest , lm * librariesmanager.LibrariesManager ) * rpc.LibrarySearchResponse {
40
40
res := []* rpc.SearchedLibrary {}
41
- status := rpc .LibrarySearchStatus_LIBRARY_SEARCH_STATUS_SUCCESS
42
-
43
- // Split on anything but 0-9, a-z or :
44
41
queryTerms := rpc .SearchTermsFromQueryString (req .GetQuery ())
45
42
46
43
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 + " "
68
50
}
69
- if match () {
51
+
52
+ if utils .Match (toTest , queryTerms ) {
70
53
res = append (res , indexLibraryToRPCSearchLibrary (lib ))
71
54
}
72
55
}
73
56
74
- return & rpc.LibrarySearchResponse {Libraries : res , Status : status }
57
+ return & rpc.LibrarySearchResponse {Libraries : res , Status : rpc . LibrarySearchStatus_LIBRARY_SEARCH_STATUS_SUCCESS }
75
58
}
76
59
77
60
// indexLibraryToRPCSearchLibrary converts a librariindex.Library to rpc.SearchLibrary
0 commit comments