Unverified Commit 3ad9cf8c authored by Massimiliano Pippi's avatar Massimiliano Pippi Committed by GitHub

Look for query string into more fields when searching for libs (#499)

* extend search fields for libs, added tests

* adjust tests
parent da8fc053
......@@ -37,7 +37,10 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchReq) (*rpc.Library
res := []*rpc.SearchedLibrary{}
for _, lib := range lm.Index.Libraries {
if strings.Contains(strings.ToLower(lib.Name), strings.ToLower(req.GetQuery())) {
qry := strings.ToLower(req.GetQuery())
if strings.Contains(strings.ToLower(lib.Name), qry) ||
strings.Contains(strings.ToLower(lib.Latest.Paragraph), qry) ||
strings.Contains(strings.ToLower(lib.Latest.Sentence), qry) {
releases := map[string]*rpc.LibraryRelease{}
for str, rel := range lib.Releases {
releases[str] = GetLibraryParameters(rel)
......
......@@ -105,4 +105,18 @@ def test_search(run_command):
result = run_command("lib search ArduinoJson --format json")
assert result.ok
libs_json = json.loads(result.stdout)
assert len(libs_json.get("libraries")) >= 1
def test_search_paragraph(run_command):
"""
Search for a string that's only present in the `paragraph` field
within the index file.
"""
assert run_command("lib update-index")
result = run_command(
'lib search "An efficient and elegant JSON library" --format json'
)
assert result.ok
libs_json = json.loads(result.stdout)
assert 1 == len(libs_json.get("libraries"))
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