Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the same property name for the query term in search requests #2214

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client_example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,8 @@ func callLibUpgradeAll(client rpc.ArduinoCoreServiceClient, instance *rpc.Instan
func callLibSearch(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance) {
libSearchResp, err := client.LibrarySearch(context.Background(),
&rpc.LibrarySearchRequest{
Instance: instance,
Query: "audio",
Instance: instance,
SearchArgs: "audio",
})

if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion commands/lib/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchRequest) (*rpc.Lib

func searchLibrary(req *rpc.LibrarySearchRequest, lm *librariesmanager.LibrariesManager) *rpc.LibrarySearchResponse {
res := []*rpc.SearchedLibrary{}
query := req.GetQuery()
query := req.GetSearchArgs()
if query == "" {
query = req.GetQuery()
}
queryTerms := utils.SearchTermsFromQueryString(query)

for _, lib := range lm.Index.Libraries {
Expand Down
6 changes: 3 additions & 3 deletions commands/lib/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestSearchLibrary(t *testing.T) {
lm := librariesmanager.NewLibraryManager(customIndexPath, nil)
lm.LoadIndex()

resp := searchLibrary(&rpc.LibrarySearchRequest{Query: "test"}, lm)
resp := searchLibrary(&rpc.LibrarySearchRequest{SearchArgs: "test"}, lm)
assert := assert.New(t)
assert.Equal(resp.GetStatus(), rpc.LibrarySearchStatus_LIBRARY_SEARCH_STATUS_SUCCESS)
assert.Equal(len(resp.GetLibraries()), 2)
Expand All @@ -45,7 +45,7 @@ func TestSearchLibrarySimilar(t *testing.T) {
lm := librariesmanager.NewLibraryManager(customIndexPath, nil)
lm.LoadIndex()

resp := searchLibrary(&rpc.LibrarySearchRequest{Query: "arduino"}, lm)
resp := searchLibrary(&rpc.LibrarySearchRequest{SearchArgs: "arduino"}, lm)
assert := assert.New(t)
assert.Equal(resp.GetStatus(), rpc.LibrarySearchStatus_LIBRARY_SEARCH_STATUS_SUCCESS)
assert.Equal(len(resp.GetLibraries()), 2)
Expand All @@ -63,7 +63,7 @@ func TestSearchLibraryFields(t *testing.T) {

query := func(q string) []string {
libs := []string{}
for _, lib := range searchLibrary(&rpc.LibrarySearchRequest{Query: q}, lm).Libraries {
for _, lib := range searchLibrary(&rpc.LibrarySearchRequest{SearchArgs: q}, lm).Libraries {
libs = append(libs, lib.Name)
}
return libs
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/arguments/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ func GetInstallableLibs() []string {
inst := instance.CreateAndInit()

libs, _ := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{
Instance: inst,
Query: "", // if no query is specified all the libs are returned
Instance: inst,
SearchArgs: "", // if no query is specified all the libs are returned
})
var res []string
// transform the data structure for the completion
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/lib/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func ParseLibraryReferenceArgs(args []string) ([]*LibraryReferenceArg, error) {
func ParseLibraryReferenceArgAndAdjustCase(instance *rpc.Instance, arg string) (*LibraryReferenceArg, error) {
libRef, _ := ParseLibraryReferenceArg(arg)
res, err := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{
Instance: instance,
Query: libRef.Name,
Instance: instance,
SearchArgs: libRef.Name,
})
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/lib/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func runSearchCommand(args []string, namesOnly bool, omitReleasesDetails bool) {

searchResp, err := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{
Instance: inst,
Query: strings.Join(args, " "),
SearchArgs: strings.Join(args, " "),
OmitReleasesDetails: omitReleasesDetails,
})
if err != nil {
Expand Down
492 changes: 253 additions & 239 deletions rpc/cc/arduino/cli/commands/v1/lib.pb.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions rpc/cc/arduino/cli/commands/v1/lib.proto
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,13 @@ message LibraryDependencyStatus {
message LibrarySearchRequest {
// Arduino Core Service instance from the `Init` response.
Instance instance = 1;
// The search query.
string query = 2;
// Deprecated. Use search_args instead.
string query = 2 [ deprecated = true ];
// Set to true to not populate the releases field in the response (may save a
// lot of bandwidth/CPU).
bool omit_releases_details = 3;
// Keywords for the search.
string search_args = 4;
}

enum LibrarySearchStatus {
Expand Down