##// END OF EJS Templates
search: add option to search within a repository group.
dan -
r3441:d273b8e9 default
parent child Browse files
Show More
@@ -347,51 +347,75 b' class HomeView(BaseAppView):'
347 347 repo_context = search_context.get('search_context[repo_view_type]')
348 348
349 349 if is_es_6 and repo_name:
350 # files
350 351 def query_modifier():
351 qry = '{} repo_name.raw:{} '.format(
352 query, searcher.escape_specials(repo_name))
352 qry = query
353 353 return {'q': qry, 'type': 'content'}
354 label = u'Search for `{}` through files in this repository.'.format(query)
354 label = u'File search for `{}` in this repository.'.format(query)
355 queries.append(
356 {
357 'id': -10,
358 'value': query,
359 'value_display': label,
360 'type': 'search',
361 'url': h.route_path('search_repo',
362 repo_name=repo_name,
363 _query=query_modifier())
364 }
365 )
366
367 # commits
368 def query_modifier():
369 qry = query
370 return {'q': qry, 'type': 'commit'}
371
372 label = u'Commit search for `{}` in this repository.'.format(query)
355 373 queries.append(
356 374 {
357 375 'id': -10,
358 376 'value': query,
359 377 'value_display': label,
360 378 'type': 'search',
361 'url': h.route_path(
362 'search_repo', repo_name=repo_name, _query=query_modifier())
363 }
364 )
365
366 def query_modifier():
367 qry = '{} repo_name.raw:{} '.format(
368 query, searcher.escape_specials(repo_name))
369 return {'q': qry, 'type': 'commit'}
370 label = u'Search for `{}` through commits in this repository.'.format(query)
371 queries.append(
372 {
373 'id': -10,
374 'value': query,
375 'value_display': label,
376 'type': 'search',
377 'url': h.route_path(
378 'search_repo', repo_name=repo_name, _query=query_modifier())
379 'url': h.route_path('search_repo',
380 repo_name=repo_name,
381 _query=query_modifier())
379 382 }
380 383 )
381 384
382 385 elif is_es_6 and repo_group_name:
386 # files
383 387 def query_modifier():
384 qry = '{} repo_name.raw:{} '.format(
385 query, searcher.escape_specials(repo_group_name + '/*'))
388 qry = query
386 389 return {'q': qry, 'type': 'content'}
387 label = u'Search for `{}` through files in this repository group'.format(query)
390
391 label = u'File search for `{}` in this repository group'.format(query)
388 392 queries.append(
389 393 {
390 394 'id': -20,
391 395 'value': query,
392 396 'value_display': label,
393 397 'type': 'search',
394 'url': h.route_path('search', _query=query_modifier())
398 'url': h.route_path('search_repo_group',
399 repo_group_name=repo_group_name,
400 _query=query_modifier())
401 }
402 )
403
404 # commits
405 def query_modifier():
406 qry = query
407 return {'q': qry, 'type': 'commit'}
408
409 label = u'Commit search for `{}` in this repository group'.format(query)
410 queries.append(
411 {
412 'id': -20,
413 'value': query,
414 'value_display': label,
415 'type': 'search',
416 'url': h.route_path('search_repo_group',
417 repo_group_name=repo_group_name,
418 _query=query_modifier())
395 419 }
396 420 )
397 421
@@ -28,7 +28,16 b' def includeme(config):'
28 28
29 29 config.add_route(
30 30 name='search_repo',
31 pattern='/{repo_name:.*?[^/]}/_search', repo_route=True)
32
33 config.add_route(
34 name='search_repo_alt',
31 35 pattern='/{repo_name:.*?[^/]}/search', repo_route=True)
32 36
37 config.add_route(
38 name='search_repo_group',
39 pattern='/{repo_group_name:.*?[^/]}/_search',
40 repo_group_route=True)
41
33 42 # Scan module for configuration decorators.
34 43 config.scan('.views', ignore='.tests')
@@ -23,8 +23,9 b' import urllib'
23 23 from pyramid.view import view_config
24 24 from webhelpers.util import update_params
25 25
26 from rhodecode.apps._base import BaseAppView, RepoAppView
27 from rhodecode.lib.auth import (LoginRequired, HasRepoPermissionAnyDecorator)
26 from rhodecode.apps._base import BaseAppView, RepoAppView, RepoGroupAppView
27 from rhodecode.lib.auth import (
28 LoginRequired, HasRepoPermissionAnyDecorator, HasRepoGroupPermissionAnyDecorator)
28 29 from rhodecode.lib.helpers import Page
29 30 from rhodecode.lib.utils2 import safe_str
30 31 from rhodecode.lib.index import searcher_from_config
@@ -34,7 +35,7 b' from rhodecode.model.validation_schema.s'
34 35 log = logging.getLogger(__name__)
35 36
36 37
37 def search(request, tmpl_context, repo_name):
38 def perform_search(request, tmpl_context, repo_name=None, repo_group_name=None):
38 39 searcher = searcher_from_config(request.registry.settings)
39 40 formatted_results = []
40 41 execution_time = ''
@@ -60,7 +61,8 b' def search(request, tmpl_context, repo_n'
60 61 def url_generator(**kw):
61 62 q = urllib.quote(safe_str(search_query))
62 63 return update_params(
63 "?q=%s&type=%s&max_lines=%s" % (q, safe_str(search_type), search_max_lines), **kw)
64 "?q=%s&type=%s&max_lines=%s" % (
65 q, safe_str(search_type), search_max_lines), **kw)
64 66
65 67 c = tmpl_context
66 68 search_query = search_params.get('search_query')
@@ -73,8 +75,8 b' def search(request, tmpl_context, repo_n'
73 75
74 76 try:
75 77 search_result = searcher.search(
76 search_query, search_type, c.auth_user, repo_name,
77 requested_page, page_limit, search_sort)
78 search_query, search_type, c.auth_user, repo_name, repo_group_name,
79 requested_page=requested_page, page_limit=page_limit, sort=search_sort)
78 80
79 81 formatted_results = Page(
80 82 search_result['results'], page=requested_page,
@@ -94,6 +96,7 b' def search(request, tmpl_context, repo_n'
94 96
95 97 c.perm_user = c.auth_user
96 98 c.repo_name = repo_name
99 c.repo_group_name = repo_group_name
97 100 c.sort = search_sort
98 101 c.url_generator = url_generator
99 102 c.errors = errors
@@ -107,7 +110,6 b' def search(request, tmpl_context, repo_n'
107 110 class SearchView(BaseAppView):
108 111 def load_default_context(self):
109 112 c = self._get_local_tmpl_context()
110
111 113 return c
112 114
113 115 @LoginRequired()
@@ -116,7 +118,7 b' class SearchView(BaseAppView):'
116 118 renderer='rhodecode:templates/search/search.mako')
117 119 def search(self):
118 120 c = self.load_default_context()
119 search(self.request, c, repo_name=None)
121 perform_search(self.request, c)
120 122 return self._get_template_context(c)
121 123
122 124
@@ -132,7 +134,28 b' class SearchRepoView(RepoAppView):'
132 134 @view_config(
133 135 route_name='search_repo', request_method='GET',
134 136 renderer='rhodecode:templates/search/search.mako')
137 @view_config(
138 route_name='search_repo_alt', request_method='GET',
139 renderer='rhodecode:templates/search/search.mako')
135 140 def search_repo(self):
136 141 c = self.load_default_context()
137 search(self.request, c, repo_name=self.db_repo_name)
142 perform_search(self.request, c, repo_name=self.db_repo_name)
138 143 return self._get_template_context(c)
144
145
146 class SearchRepoGroupView(RepoGroupAppView):
147 def load_default_context(self):
148 c = self._get_local_tmpl_context()
149 c.active = 'search'
150 return c
151
152 @LoginRequired()
153 @HasRepoGroupPermissionAnyDecorator(
154 'group.read', 'group.write', 'group.admin')
155 @view_config(
156 route_name='search_repo_group', request_method='GET',
157 renderer='rhodecode:templates/search/search.mako')
158 def search_repo_group(self):
159 c = self.load_default_context()
160 perform_search(self.request, c, repo_group_name=self.db_repo_group_name)
161 return self._get_template_context(c)
@@ -53,7 +53,8 b' class BaseSearcher(object):'
53 53 def cleanup(self):
54 54 pass
55 55
56 def search(self, query, document_type, search_user, repo_name=None,
56 def search(self, query, document_type, search_user,
57 repo_name=None, repo_group_name=None,
57 58 raise_on_exc=True):
58 59 raise Exception('NotImplemented')
59 60
@@ -100,8 +100,8 b' class WhooshSearcher(BaseSearcher):'
100 100 return query
101 101
102 102 def search(self, query, document_type, search_user,
103 repo_name=None, requested_page=1, page_limit=10, sort=None,
104 raise_on_exc=True):
103 repo_name=None, repo_group_name=None,
104 requested_page=1, page_limit=10, sort=None, raise_on_exc=True):
105 105
106 106 original_query = query
107 107 query = self._extend_query(query)
General Comments 0
You need to be logged in to leave comments. Login now