Score based on the robot short name

This commit is contained in:
Joseph Schorr 2015-04-20 12:51:47 -04:00
parent d714c00ddb
commit 16e05e83b1

View file

@ -137,7 +137,7 @@ class FindRepositories(ApiResource):
def search_entity_view(username, entity):
def search_entity_view(username, entity, get_short_name=None):
kind = 'user'
avatar_data = avatar.get_data_for_user(entity)
href = '/user/' + entity.username
@ -156,7 +156,7 @@ def search_entity_view(username, entity):
kind = 'robot'
avatar_data = None
return {
data = {
'kind': kind,
'avatar': avatar_data,
'name': entity.username,
@ -164,6 +164,11 @@ def search_entity_view(username, entity):
'href': href
}
if get_short_name:
data['short_name'] = get_short_name(entity.username)
return data
def conduct_team_search(username, query, encountered_teams, results):
""" Finds the matching teams where the user is a member. """
@ -242,9 +247,12 @@ def conduct_namespace_search(username, query, results):
def conduct_robot_search(username, query, results):
""" Finds matching robot accounts. """
def get_short_name(name):
return parse_robot_username(name)[1]
matching_robots = model.get_matching_robots(query, username, limit=5)
for robot in matching_robots:
results.append(search_entity_view(username, robot))
results.append(search_entity_view(username, robot, get_short_name))
@resource('/v1/find/all')
@ -282,6 +290,7 @@ class ConductSearch(ApiResource):
# Modify the results' scores via how close the query term is to each result's name.
for result in results:
result['score'] = result['score'] * liquidmetal.score(result['name'], query)
name = result.get('short_name', result['name'])
result['score'] = result['score'] * liquidmetal.score(name, query)
return {'results': sorted(results, key=itemgetter('score'), reverse=True)}