Skip to content

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

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

Merged
merged 2 commits into from
Dec 4, 2019
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
5 changes: 4 additions & 1 deletion commands/lib/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions test/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))