Unverified Commit c6afedee authored by MatteoPologruto's avatar MatteoPologruto Committed by GitHub

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

* Deprecate `query` in favor of `search_args`

* Give priority to `search_args` if possible
parent 5725c027
......@@ -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 {
......
......@@ -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 {
......
......@@ -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)
......@@ -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)
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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 {
......
This diff is collapsed.
......@@ -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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment