diff --git a/data/model.py b/data/model.py index 2fc075669..d48a46a83 100644 --- a/data/model.py +++ b/data/model.py @@ -110,9 +110,22 @@ def get_visible_repositories(username=None): def get_matching_repositories(repo_term, username=None): + namespace_term = repo_term + name_term = repo_term + visible = get_visible_repositories(username) - search_clauses = (Repository.name ** ('%' + repo_term + '%') | - Repository.namespace ** ('%' + repo_term + '%')) + + search_clauses = (Repository.name ** ('%' + name_term + '%') | + Repository.namespace ** ('%' + namespace_term + '%')) + + # Handle the case where the user has already entered a namespace path. + if repo_term.find('/') > 0: + parts = repo_term.split('/', 1) + namespace_term = '/'.join(parts[:-1]) + name_term = parts[-1] + + search_clauses = (Repository.name ** ('%' + name_term + '%') & + Repository.namespace ** ('%' + namespace_term + '%')) final = visible.where(search_clauses).limit(10) return list(final) diff --git a/endpoints/api.py b/endpoints/api.py index ddc9bfa5e..1ac285f10 100644 --- a/endpoints/api.py +++ b/endpoints/api.py @@ -67,8 +67,9 @@ def create_repo_api(): pass -@app.route('/api/repository/find/', methods=['GET']) -def match_repos_api(prefix): +@app.route('/api/find/repository', methods=['GET']) +def match_repos_api(): + prefix = request.args.get('query', '') def repo_view(repo): return { 'namespace': repo.namespace, diff --git a/static/js/controllers.js b/static/js/controllers.js index 2ccf35b5f..09c82bd32 100644 --- a/static/js/controllers.js +++ b/static/js/controllers.js @@ -43,7 +43,7 @@ function HeaderCtrl($scope, UserService) { $('#repoSearch').typeahead({ name: 'repositories', remote: { - url: '/api/repository/find/%QUERY', + url: '/api/find/repository?query=%QUERY', filter: function(data) { var datums = []; for (var i = 0; i < data.repositories.length; ++i) {