Skip to content

Commit 28dd57d

Browse files
committed
Moving SearchTermsFromQueryString into proper place
1 parent ebb55e3 commit 28dd57d

File tree

4 files changed

+12
-33
lines changed

4 files changed

+12
-33
lines changed

Diff for: arduino/utils/search.go

+10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ func removeDiatrics(s string) (string, error) {
4343
return s, nil
4444
}
4545

46+
// SearchTermsFromQueryString returns the terms inside the query string.
47+
// All non alphanumeric characters (expect ':') are considered separators.
48+
// All search terms are converted to lowercase.
49+
func SearchTermsFromQueryString(query string) []string {
50+
// Split on anything but 0-9, a-z or :
51+
return strings.FieldsFunc(strings.ToLower(query), func(r rune) bool {
52+
return !unicode.IsLetter(r) && !unicode.IsNumber(r) && r != ':'
53+
})
54+
}
55+
4656
// Match returns true if all substrings are contained in str.
4757
// Both str and substrings are transforms to lower case and have their
4858
// accents and other unicode diatrics removed.

Diff for: commands/core/search.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
4040
vid, pid := req.SearchArgs[:4], req.SearchArgs[5:]
4141
res = pme.FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid)
4242
} else {
43-
searchArgs := rpc.SearchTermsFromQueryString(req.SearchArgs)
43+
searchArgs := utils.SearchTermsFromQueryString(req.SearchArgs)
4444
allVersions := req.AllVersions
4545
for _, targetPackage := range pme.GetPackages() {
4646
for _, platform := range targetPackage.Platforms {

Diff for: commands/lib/search.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchRequest) (*rpc.Lib
3838

3939
func searchLibrary(req *rpc.LibrarySearchRequest, lm *librariesmanager.LibrariesManager) *rpc.LibrarySearchResponse {
4040
res := []*rpc.SearchedLibrary{}
41-
queryTerms := rpc.SearchTermsFromQueryString(req.GetQuery())
41+
queryTerms := utils.SearchTermsFromQueryString(req.GetQuery())
4242

4343
for _, lib := range lm.Index.Libraries {
4444
toTest := lib.Name + " " +

Diff for: rpc/cc/arduino/cli/commands/v1/search.go

-31
This file was deleted.

0 commit comments

Comments
 (0)