Skip to content

Commit ba3ea2f

Browse files
authored
Update search for keyword substrings (#50)
* Update search on keywords * bump version to 1.1.2
1 parent 25f0491 commit ba3ea2f

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

Diff for: ggd/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "1.1.1"
1+
__version__ = "1.1.2"
22

Diff for: ggd/search.py

+19-5
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def add_search(p):
6262
c.add_argument(
6363
"-m",
6464
"--match-score",
65-
default="75",
66-
help="(Optional) A score between 0 and 100 to use to filter the results by. (Default = 75). The lower the number the more results will be output",
65+
default="90",
66+
help="(Optional) A score between 0 and 100 to use to filter the results by. (Default = 90). The lower the number the more results will be output",
6767
)
6868
c.add_argument(
6969
"-c",
@@ -156,6 +156,7 @@ def search_packages(json_dict, search_terms, search_type="both", score_cutoff=50
156156
++++++++
157157
1) (dict) A list of pkg names who's either name or keyword match score reached the score cutoff
158158
"""
159+
import re
159160
from collections import defaultdict
160161

161162
from fuzzywuzzy import fuzz, process
@@ -186,7 +187,12 @@ def search_packages(json_dict, search_terms, search_type="both", score_cutoff=50
186187
keyword_max_score = max(
187188
[
188189
fuzz.ratio(term.lower(), x.lower())
189-
for x in json_dict["packages"][pkg]["keywords"]
190+
for x in [
191+
subkeyword
192+
for keyword in json_dict["packages"][pkg]["keywords"]
193+
for subkeyword in re.split("-|_", keyword.strip())
194+
]
195+
+ json_dict["packages"][pkg]["keywords"]
190196
]
191197
)
192198

@@ -463,8 +469,16 @@ def print_summary(search_terms, json_dict, match_list, installed_pkgs, installed
463469
else:
464470
from .utils import check_for_meta_recipes
465471

466-
results.append("\n\tTo install run:\n\t\tggd install %s %s" %(pkg, "--id <meta-recipe ID>" if check_for_meta_recipes(pkg,json_dict) else "" ))
467-
472+
results.append(
473+
"\n\tTo install run:\n\t\tggd install %s %s"
474+
% (
475+
pkg,
476+
"--id <meta-recipe ID>"
477+
if check_for_meta_recipes(pkg, json_dict)
478+
else "",
479+
)
480+
)
481+
468482
print("\n\n".join(results))
469483
print("\n", dash)
470484

0 commit comments

Comments
 (0)