##// END OF EJS Templates
Issue #5548 - Pass repo_group_name
pc -
r3508:46984709 tip default
parent child Browse files
Show More
@@ -1,109 +1,109 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2011-2018 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21
22 22 import logging
23 23
24 24 from rhodecode.api import jsonrpc_method
25 25 from rhodecode.api.exc import JSONRPCValidationError
26 26 from rhodecode.api.utils import Optional
27 27 from rhodecode.lib.index import searcher_from_config
28 28 from rhodecode.model import validation_schema
29 29 from rhodecode.model.validation_schema.schemas import search_schema
30 30
31 31 log = logging.getLogger(__name__)
32 32
33 33
34 34 @jsonrpc_method()
35 35 def search(request, apiuser, search_query, search_type, page_limit=Optional(10), page=Optional(1), search_sort=Optional('newfirst'), repo_name=Optional(None), repo_group_name=Optional(None)):
36 36 """
37 37 Search
38 38
39 39 :param apiuser: This is filled automatically from the |authtoken|.
40 40 :type apiuser: AuthUser
41 41 :param search_query: Search query.
42 42 :type search_query: str
43 43 :param search_type: Search type. The following are valid options:
44 44 * commit
45 45 * content
46 46 * path
47 47 :type search_type: str
48 48 :param page_limit: Page item limit, from 1 to 500. Default 10 items.
49 49 :type page_limit: Optional(int)
50 50 :param page: Page number. Default first page.
51 51 :type page: Optional(int)
52 52 :param search_sort: Search sort order. Default newfirst. The following are valid options:
53 53 * newfirst
54 54 * oldfirst
55 55 :type search_sort: Optional(str)
56 56 :param repo_name: Filter by one repo. Default is all.
57 57 :type repo_name: Optional(str)
58 58 :param repo_group_name: Filter by one repo group. Default is all.
59 59 :type repo_group_name: Optional(str)
60 60 """
61 61
62 62 searcher = searcher_from_config(request.registry.settings)
63 63 data = {'execution_time': ''}
64 64 repo_name = Optional.extract(repo_name)
65 65 repo_group_name = Optional.extract(repo_group_name)
66 66
67 67 schema = search_schema.SearchParamsSchema()
68 68
69 69 search_params = {}
70 70 try:
71 71 search_params = schema.deserialize(
72 72 dict(search_query=search_query,
73 73 search_type=search_type,
74 74 search_sort=Optional.extract(search_sort),
75 75 page_limit=Optional.extract(page_limit),
76 76 requested_page=Optional.extract(page))
77 77 )
78 78 except validation_schema.Invalid as err:
79 79 raise JSONRPCValidationError(colander_exc=err)
80 80
81 81 search_query = search_params.get('search_query')
82 82 search_type = search_params.get('search_type')
83 83 search_sort = search_params.get('search_sort')
84 84
85 85 if search_params.get('search_query'):
86 86 page_limit = search_params['page_limit']
87 87 requested_page = search_params['requested_page']
88 88
89 89 try:
90 90 search_result = searcher.search(
91 search_query, search_type, apiuser, repo_name,
92 requested_page, page_limit, search_sort)
91 search_query, search_type, apiuser, repo_name, repo_group_name,
92 requested_page=requested_page, page_limit=page_limit, sort=search_sort)
93 93
94 94 data.update(dict(
95 95 results=list(search_result['results']), page=requested_page,
96 96 item_count=search_result['count'],
97 97 items_per_page=page_limit))
98 98 finally:
99 99 searcher.cleanup()
100 100
101 101 if not search_result['error']:
102 102 data['execution_time'] = '%s results (%.3f seconds)' % (
103 103 search_result['count'],
104 104 search_result['runtime'])
105 105 else:
106 106 node = schema['search_query']
107 107 raise JSONRPCValidationError(colander_exc=validation_schema.Invalid(node, search_result['error']))
108 108
109 109 return data
General Comments 11
Under Review
pc
author

Auto status change to "Under Review"

Approved

CLA FOUND and APPROVED

Under Review
pc
author

Pull request updated. Auto status change to "Under Review"

Changed commits:
  * 2 added
  * 0 removed

Changed files:
  * M rhodecode/api/views/search_api.py
Approved

CLA FOUND and APPROVED

Approved

Status change > Approved

Approved

Thanks for contribution. We'll merge this manually.

You need to be logged in to leave comments. Login now