Fix search to return better results by searching for robots and namespaces in different queries.

This commit is contained in:
Joseph Schorr 2015-04-09 12:57:20 -04:00
parent 3707feaf5d
commit 396cba64e6
3 changed files with 46 additions and 29 deletions

View file

@ -227,22 +227,18 @@ def conduct_repo_search(username, query, results):
})
def conduct_entity_search(username, query, results):
""" Finds matching users, robots and organizations. """
matching_entities = model.get_matching_entities(query)
entity_count = 0
def conduct_namespace_search(username, query, results):
""" Finds matching users and organizations. """
matching_entities = model.get_matching_user_namespaces(query, username, limit=5)
for entity in matching_entities:
# If the entity is a robot, filter it to only match those that are under the current
# user or can be administered by the organization.
if entity.robot:
orgname = parse_robot_username(entity.username)[0]
if not AdministerOrganizationPermission(orgname).can() and not orgname == username:
continue
results.append(search_entity_view(username, entity))
entity_count = entity_count + 1
if entity_count >= 5:
break
def conduct_robot_search(username, query, results):
""" Finds matching robot accounts. """
matching_robots = model.get_matching_robots(query, username, limit=5)
for robot in matching_robots:
results.append(search_entity_view(username, robot))
@resource('/v1/find/all')
@ -269,11 +265,14 @@ class ConductSearch(ApiResource):
conduct_team_search(username, query, encountered_teams, results)
conduct_admined_team_search(username, query, encountered_teams, results)
# Search for robot accounts.
conduct_robot_search(username, query, results)
# Search for repos.
conduct_repo_search(username, query, results)
# Search for users, orgs and robots.
conduct_entity_search(username, query, results)
# Search for users and orgs.
conduct_namespace_search(username, query, results)
# Modify the results' scores via how close the query term is to each result's name.
for result in results: