##// END OF EJS Templates
search: allow quick search for path globally
dan -
r3542:40ac848d default
parent child Browse files
Show More
@@ -288,6 +288,47 b' class HomeView(BaseAppView):'
288 commits.append(commit_entry)
288 commits.append(commit_entry)
289 return commits
289 return commits
290
290
291 def _get_path_list(self, auth_user, searcher, query):
292 org_query = query
293 if not query or len(query) < 3 or not searcher:
294 return []
295
296 paths_re = re.compile('(?:file:)(.{1,})').findall(query)
297 if len(paths_re) != 1:
298 return []
299 file_path = paths_re[0]
300
301 search_path = searcher.escape_specials(file_path)
302 result = searcher.search(
303 'file.raw:*{}*'.format(search_path), 'path', auth_user,
304 raise_on_exc=False)
305
306 files = []
307 for entry in result['results']:
308 repo_data = {
309 'repository_id': entry.get('repository_id'),
310 'repository_type': entry.get('repo_type'),
311 'repository_name': entry.get('repository'),
312 }
313
314 file_entry = {
315 'id': entry['commit_id'],
316 'value': org_query,
317 'value_display': '`{}` file: {}'.format(
318 entry['repository'], entry['file']),
319 'type': 'file',
320 'repo': entry['repository'],
321 'repo_data': repo_data,
322
323 'url': h.route_path(
324 'repo_files',
325 repo_name=entry['repository'], commit_id=entry['commit_id'],
326 f_path=entry['file'])
327 }
328
329 files.append(file_entry)
330 return files
331
291 @LoginRequired()
332 @LoginRequired()
292 @view_config(
333 @view_config(
293 route_name='repo_list_data', request_method='GET',
334 route_name='repo_list_data', request_method='GET',
@@ -518,6 +559,17 b' class HomeView(BaseAppView):'
518 for commit in commits:
559 for commit in commits:
519 res.append(commit)
560 res.append(commit)
520
561
562 paths = self._get_path_list(c.auth_user, searcher, query)
563 if paths:
564 unique_repos = collections.OrderedDict()
565 for path in paths:
566 repo_name = path['repo']
567 unique_repos.setdefault(repo_name, []).append(path)
568
569 for repo, paths in unique_repos.items():
570 for path in paths:
571 res.append(path)
572
521 return {'suggestions': res}
573 return {'suggestions': res}
522
574
523 def _get_groups_and_repos(self, repo_group_id=None):
575 def _get_groups_and_repos(self, repo_group_id=None):
@@ -80,6 +80,13 b' class BaseSearcher(object):'
80 def extract_search_tags(query):
80 def extract_search_tags(query):
81 return []
81 return []
82
82
83 @staticmethod
84 def escape_specials(val):
85 """
86 Handle and escape reserved chars for search
87 """
88 return val
89
83
90
84 def search_config(config, prefix='search.'):
91 def search_config(config, prefix='search.'):
85 _config = {}
92 _config = {}
@@ -503,6 +503,8 b''
503 user_group:devops, to search for user groups
503 user_group:devops, to search for user groups
504
504
505 commit:efced4, to search for commits
505 commit:efced4, to search for commits
506
507 file:models.py, to search for file paths
506 </div>
508 </div>
507 </li>
509 </li>
508
510
@@ -693,6 +695,16 b''
693 icon += '<i class="icon-tag"></i>';
695 icon += '<i class="icon-tag"></i>';
694 }
696 }
695 }
697 }
698 // file
699 else if (searchType === 'file') {
700 var repo_data = data['repo_data'];
701 var repoIcon = getRepoIcon(repo_data['repository_type']);
702 if (repoIcon) {
703 icon += repoIcon;
704 } else {
705 icon += '<i class="icon-tag"></i>';
706 }
707 }
696
708
697 var tmpl = '<div class="ac-container-wrap">{0}{1}</div>';
709 var tmpl = '<div class="ac-container-wrap">{0}{1}</div>';
698 return tmpl.format(icon, valueDisplay);
710 return tmpl.format(icon, valueDisplay);
General Comments 0
You need to be logged in to leave comments. Login now