##// END OF EJS Templates
search: sort commit messages by date rather than revision
dan -
r71:37d53e52 default
parent child Browse files
Show More
@@ -56,23 +56,25 b' class SearchController(BaseRepoControlle'
56 56 search_params = schema.deserialize(
57 57 dict(search_query=request.GET.get('q'),
58 58 search_type=request.GET.get('type'),
59 search_sort=request.GET.get('sort'),
59 60 page_limit=request.GET.get('page_limit'),
60 61 requested_page=request.GET.get('page'))
61 62 )
62 63 except validation_schema.Invalid as e:
63 64 errors = e.children
64 65
66 def url_generator(**kw):
67 q = urllib.quote(safe_str(search_query))
68 return update_params(
69 "?q=%s&type=%s" % (q, safe_str(search_type)), **kw)
70
65 71 search_query = search_params.get('search_query')
66 72 search_type = search_params.get('search_type')
67
73 search_sort = search_params.get('search_sort')
68 74 if search_params.get('search_query'):
69 75 page_limit = search_params['page_limit']
70 76 requested_page = search_params['requested_page']
71 77
72 def url_generator(**kw):
73 q = urllib.quote(safe_str(search_query))
74 return update_params(
75 "?q=%s&type=%s" % (q, safe_str(search_type)), **kw)
76 78
77 79 c.perm_user = AuthUser(user_id=c.rhodecode_user.user_id,
78 80 ip_addr=self.ip_addr)
@@ -80,7 +82,7 b' class SearchController(BaseRepoControlle'
80 82 try:
81 83 search_result = searcher.search(
82 84 search_query, search_type, c.perm_user, repo_name,
83 requested_page, page_limit)
85 requested_page, page_limit, search_sort)
84 86
85 87 formatted_results = Page(
86 88 search_result['results'], page=requested_page,
@@ -98,6 +100,8 b' class SearchController(BaseRepoControlle'
98 100 errors = [
99 101 validation_schema.Invalid(node, search_result['error'])]
100 102
103 c.sort = search_sort
104 c.url_generator = url_generator
101 105 c.errors = errors
102 106 c.formatted_results = formatted_results
103 107 c.runtime = execution_time
@@ -100,7 +100,7 b' class Search(BaseSearch):'
100 100 return query
101 101
102 102 def search(self, query, document_type, search_user, repo_name=None,
103 requested_page=1, page_limit=10):
103 requested_page=1, page_limit=10, sort=None):
104 104
105 105 original_query = query
106 106 query = self._extend_query(query)
@@ -123,13 +123,18 b' class Search(BaseSearch):'
123 123 query = qp.parse(unicode(query))
124 124 log.debug('query: %s (%s)' % (query, repr(query)))
125 125
126 sortedby = None
126 reverse, sortedby = False, None
127 127 if search_type == 'message':
128 sortedby = sorting.FieldFacet('commit_idx', reverse=True)
128 if sort == 'oldfirst':
129 sortedby = 'date'
130 reverse = False
131 elif sort == 'newfirst':
132 sortedby = 'date'
133 reverse = True
129 134
130 135 whoosh_results = self.searcher.search(
131 136 query, filter=allowed_repos_filter, limit=None,
132 sortedby=sortedby,)
137 sortedby=sortedby, reverse=reverse)
133 138
134 139 # fixes for 32k limit that whoosh uses for highlight
135 140 whoosh_results.fragmenter.charlimit = None
@@ -51,6 +51,11 b' class SearchParamsSchema(colander.Mappin'
51 51 colander.String(),
52 52 missing='content',
53 53 validator=colander.OneOf(['content', 'path', 'commit', 'repository']))
54 search_sort = colander.SchemaNode(
55 colander.String(),
56 missing='newfirst',
57 validator=colander.OneOf(
58 ['oldfirst', 'newfirst']))
54 59 page_limit = colander.SchemaNode(
55 60 colander.Integer(),
56 61 missing=10,
@@ -6,7 +6,13 b''
6 6 <th>${_('Commit')}</th>
7 7 <th></th>
8 8 <th>${_('Commit message')}</th>
9 <th>${_('Age')}</th>
9 <th>
10 %if c.sort == 'newfirst':
11 <a href="${c.url_generator(sort='oldfirst')}">${_('Age (new first)')}</a>
12 %else:
13 <a href="${c.url_generator(sort='newfirst')}">${_('Age (old first)')}</a>
14 %endif
15 </th>
10 16 <th>${_('Author')}</th>
11 17 </tr>
12 18 %for entry in c.formatted_results:
General Comments 0
You need to be logged in to leave comments. Login now