diff --git a/endpoints/api/search.py b/endpoints/api/search.py index c8a9be22d..582d25f50 100644 --- a/endpoints/api/search.py +++ b/endpoints/api/search.py @@ -18,6 +18,12 @@ from util.names import parse_robot_username import anunidecode # Don't listen to pylint's lies. This import is required. import math + +ENTITY_SEARCH_SCORE = 1 +TEAM_SEARCH_SCORE = 2 +REPOSITORY_SEARCH_SCORE = 4 + + @resource('/v1/entities/link/') @internal_only class LinkExternalEntity(ApiResource): @@ -179,7 +185,7 @@ def search_entity_view(username, entity, get_short_name=None): 'kind': kind, 'avatar': avatar_data, 'name': entity.username, - 'score': 1, + 'score': ENTITY_SEARCH_SCORE, 'href': href } @@ -203,7 +209,7 @@ def conduct_team_search(username, query, encountered_teams, results): 'name': team.name, 'organization': search_entity_view(username, team.organization), 'avatar': avatar.get_data_for_team(team), - 'score': 2, + 'score': TEAM_SEARCH_SCORE, 'href': '/organization/' + team.organization.username + '/teams/' + team.name }) @@ -222,7 +228,7 @@ def conduct_admined_team_search(username, query, encountered_teams, results): 'name': team.name, 'organization': search_entity_view(username, team.organization), 'avatar': avatar.get_data_for_team(team), - 'score': 2, + 'score': TEAM_SEARCH_SCORE, 'href': '/organization/' + team.organization.username + '/teams/' + team.name }) @@ -238,7 +244,7 @@ def conduct_repo_search(username, query, results): 'name': repo.name, 'description': repo.description, 'is_public': model.repository.is_repository_public(repo), - 'score': 4, + 'score': REPOSITORY_SEARCH_SCORE, 'href': '/repository/' + repo.namespace_user.username + '/' + repo.name })