Skip to content
This repository has been archived by the owner on Aug 4, 2018. It is now read-only.

Commit

Permalink
Add search param q
Browse files Browse the repository at this point in the history
  • Loading branch information
Fingercomp committed Nov 23, 2016
1 parent a8bd373 commit 7bae74b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
@@ -1,6 +1,7 @@
3.1.0
-----
- Added ``owners`` search param.
- Added ``q`` search param.
- Added group ``~banned``.

3.0.3
Expand Down
9 changes: 9 additions & 0 deletions hel/tests/test_views.py
Expand Up @@ -260,6 +260,15 @@ def test_pkg_search_screen_url(self):
(['http://img.example.com/img32'], [self.pkg3],)
]

@one_value_param('q')
def test_pkg_search_q(self):
return [
('root', [self.pkg1, self.pkg2, self.pkg3],),
('Change package "My first"', [self.pkg1],),
('hello people xD', [],),
('test img-2 2 21.', [self.pkg2],)
]

def test_bad_search_param(self):
try:
PackagesSearcher({'hi': ['test']})()
Expand Down
47 changes: 47 additions & 0 deletions hel/utils/query.py
Expand Up @@ -247,6 +247,53 @@ def search(pkg):

return search

@_only_one_param
def q(param):

def search(pkg):
phrases = parse_search_phrase(param)
for phrase in phrases:
found = False
for k in ["name", "description", "short_description"]:
if phrase in pkg[k]:
found = True
break
if found:
continue

for k in ["owners", "authors", "license", "tags"]:
for v in pkg[k]:
if phrase in v:
found = True
break
if found:
break
if found:
continue

for k, screenshot in pkg["screenshots"].items():
if phrase in screenshot:
found = True
break
if found:
continue

for k, version in pkg["versions"].items():
if phrase in version["changes"]:
found = True
break
if found:
continue

# If we reached this line, `continue` lines weren't executed.
# It means that the phrase was not found.
# As all phrases must be found, we terminate the loop.
return False

return True

return search


class PackagesSearcher:

Expand Down

0 comments on commit 7bae74b

Please sign in to comment.