Add search tests

This commit is contained in:
Joseph Schorr 2015-04-07 14:05:12 -04:00
parent 1b56567268
commit 40a6892a49
3 changed files with 92 additions and 9 deletions

View file

@ -113,7 +113,10 @@ class ConductSearch(ApiResource):
@nickname('conductSearch')
def get(self, args):
""" Get a list of entities and resources that match the specified query. """
prefix = args['query']
query = args['query']
if not query:
return {'results': []}
username = None
results = []
@ -145,7 +148,7 @@ class ConductSearch(ApiResource):
# Find the matching teams where the user is a member.
encountered_teams = set()
matching_teams = model.get_matching_user_teams(prefix, get_authenticated_user())
matching_teams = model.get_matching_user_teams(query, get_authenticated_user())
for team in matching_teams:
if team.id in encountered_teams:
continue
@ -162,7 +165,7 @@ class ConductSearch(ApiResource):
})
# Find matching teams in orgs admined by the user.
matching_teams = model.get_matching_admined_teams(prefix, get_authenticated_user())
matching_teams = model.get_matching_admined_teams(query, get_authenticated_user())
for team in matching_teams:
if team.id in encountered_teams:
continue
@ -180,7 +183,7 @@ class ConductSearch(ApiResource):
# Find the matching repositories.
matching_repos = model.get_matching_repositories(prefix, username)
matching_repos = model.get_matching_repositories(query, username)
matching_repo_counts = {t[0]: t[1] for t in model.get_repository_pull_counts(matching_repos)}
for repo in matching_repos:
@ -195,12 +198,12 @@ class ConductSearch(ApiResource):
})
# Find the matching users, robots and organizations.
matching_entities = model.get_matching_user_entities(prefix, get_authenticated_user())
matching_entities = model.get_matching_user_entities(query, get_authenticated_user())
for entity in matching_entities:
results.append(entity_view(entity))
for result in results:
result['score'] = result['score'] * liquidmetal.score(result['name'], prefix)
result['score'] = result['score'] * liquidmetal.score(result['name'], query)
return {'results': sorted(results, key=itemgetter('score'), reverse=True)}