Merge pull request #2617 from coreos-inc/search-ordering
Search ordering and performance fixes
This commit is contained in:
commit
5d88bccef7
3 changed files with 40 additions and 10 deletions
|
@ -464,7 +464,13 @@ def _filter_repositories_visible_to_username(unfiltered_query, filter_username,
|
||||||
.where(Repository.id << list(new_unfiltered_ids)))
|
.where(Repository.id << list(new_unfiltered_ids)))
|
||||||
|
|
||||||
filtered = _basequery.filter_to_repos_for_user(query, filter_username, repo_kind=repo_kind)
|
filtered = _basequery.filter_to_repos_for_user(query, filter_username, repo_kind=repo_kind)
|
||||||
for filtered_repo in filtered:
|
|
||||||
|
# Sort the filtered repositories by their initial order.
|
||||||
|
all_filtered_repos = list(filtered)
|
||||||
|
all_filtered_repos.sort(key=lambda repo: found_ids.index(repo.id))
|
||||||
|
|
||||||
|
# Yield the repositories in sorted order.
|
||||||
|
for filtered_repo in all_filtered_repos:
|
||||||
yield filtered_repo
|
yield filtered_repo
|
||||||
|
|
||||||
# If the number of found IDs is less than the chunk count, then we're done.
|
# If the number of found IDs is less than the chunk count, then we're done.
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
from endpoints.api import (ApiResource, parse_args, query_param, truthy_bool, nickname, resource,
|
from endpoints.api import (ApiResource, parse_args, query_param, truthy_bool, nickname, resource,
|
||||||
require_scope, path_param, internal_only, Unauthorized, InvalidRequest,
|
require_scope, path_param, internal_only, Unauthorized, InvalidRequest,
|
||||||
show_if)
|
show_if)
|
||||||
|
from data.database import Repository
|
||||||
from data import model
|
from data import model
|
||||||
from auth.permissions import (OrganizationMemberPermission, ReadRepositoryPermission,
|
from auth.permissions import (OrganizationMemberPermission, ReadRepositoryPermission,
|
||||||
UserAdminPermission, AdministerOrganizationPermission,
|
UserAdminPermission, AdministerOrganizationPermission,
|
||||||
|
@ -266,7 +267,7 @@ def conduct_robot_search(username, query, results):
|
||||||
|
|
||||||
|
|
||||||
def repo_result_view(repo, username, last_modified=None, stars=None, popularity=None):
|
def repo_result_view(repo, username, last_modified=None, stars=None, popularity=None):
|
||||||
kind = 'application' if repo.kind.name == 'application' else 'repository'
|
kind = 'application' if Repository.kind.get_name(repo.kind_id) == 'application' else 'repository'
|
||||||
view = {
|
view = {
|
||||||
'kind': kind,
|
'kind': kind,
|
||||||
'title': 'app' if kind == 'application' else 'repo',
|
'title': 'app' if kind == 'application' else 'repo',
|
||||||
|
|
|
@ -1,12 +1,35 @@
|
||||||
from endpoints.api.search import ConductRepositorySearch
|
import pytest
|
||||||
|
|
||||||
|
from playhouse.test_utils import assert_query_count
|
||||||
|
|
||||||
|
from data.model import _basequery
|
||||||
|
from endpoints.api.search import ConductRepositorySearch, ConductSearch
|
||||||
from endpoints.api.test.shared import client_with_identity, conduct_api_call
|
from endpoints.api.test.shared import client_with_identity, conduct_api_call
|
||||||
from test.fixtures import *
|
from test.fixtures import *
|
||||||
|
|
||||||
def test_repository_search(client):
|
@pytest.mark.parametrize('query, expected_query_count', [
|
||||||
|
('simple', 7),
|
||||||
|
('public', 6),
|
||||||
|
('repository', 6),
|
||||||
|
])
|
||||||
|
def test_repository_search(query, expected_query_count, client):
|
||||||
with client_with_identity('devtable', client) as cl:
|
with client_with_identity('devtable', client) as cl:
|
||||||
params = {'query': 'simple'}
|
params = {'query': query}
|
||||||
result = conduct_api_call(cl, ConductRepositorySearch, 'GET', params, None, 200).json
|
with assert_query_count(expected_query_count):
|
||||||
assert not result['has_additional']
|
result = conduct_api_call(cl, ConductRepositorySearch, 'GET', params, None, 200).json
|
||||||
assert result['start_index'] == 0
|
assert result['start_index'] == 0
|
||||||
assert result['page'] == 1
|
assert result['page'] == 1
|
||||||
assert result['results'][0]['name'] == 'simple'
|
assert len(result['results'])
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('query, expected_query_count', [
|
||||||
|
('simple', 8),
|
||||||
|
('public', 8),
|
||||||
|
('repository', 8),
|
||||||
|
])
|
||||||
|
def test_search_query_count(query, expected_query_count, client):
|
||||||
|
with client_with_identity('devtable', client) as cl:
|
||||||
|
params = {'query': query}
|
||||||
|
with assert_query_count(expected_query_count):
|
||||||
|
result = conduct_api_call(cl, ConductSearch, 'GET', params, None, 200).json
|
||||||
|
assert len(result['results'])
|
||||||
|
|
Reference in a new issue