Show More
@@ -56,23 +56,25 b' class SearchController(BaseRepoControlle' | |||||
56 | search_params = schema.deserialize( |
|
56 | search_params = schema.deserialize( | |
57 | dict(search_query=request.GET.get('q'), |
|
57 | dict(search_query=request.GET.get('q'), | |
58 | search_type=request.GET.get('type'), |
|
58 | search_type=request.GET.get('type'), | |
|
59 | search_sort=request.GET.get('sort'), | |||
59 | page_limit=request.GET.get('page_limit'), |
|
60 | page_limit=request.GET.get('page_limit'), | |
60 | requested_page=request.GET.get('page')) |
|
61 | requested_page=request.GET.get('page')) | |
61 | ) |
|
62 | ) | |
62 | except validation_schema.Invalid as e: |
|
63 | except validation_schema.Invalid as e: | |
63 | errors = e.children |
|
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 | search_query = search_params.get('search_query') |
|
71 | search_query = search_params.get('search_query') | |
66 | search_type = search_params.get('search_type') |
|
72 | search_type = search_params.get('search_type') | |
67 |
|
73 | search_sort = search_params.get('search_sort') | ||
68 | if search_params.get('search_query'): |
|
74 | if search_params.get('search_query'): | |
69 | page_limit = search_params['page_limit'] |
|
75 | page_limit = search_params['page_limit'] | |
70 | requested_page = search_params['requested_page'] |
|
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 | c.perm_user = AuthUser(user_id=c.rhodecode_user.user_id, |
|
79 | c.perm_user = AuthUser(user_id=c.rhodecode_user.user_id, | |
78 | ip_addr=self.ip_addr) |
|
80 | ip_addr=self.ip_addr) | |
@@ -80,7 +82,7 b' class SearchController(BaseRepoControlle' | |||||
80 | try: |
|
82 | try: | |
81 | search_result = searcher.search( |
|
83 | search_result = searcher.search( | |
82 | search_query, search_type, c.perm_user, repo_name, |
|
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 | formatted_results = Page( |
|
87 | formatted_results = Page( | |
86 | search_result['results'], page=requested_page, |
|
88 | search_result['results'], page=requested_page, | |
@@ -98,6 +100,8 b' class SearchController(BaseRepoControlle' | |||||
98 | errors = [ |
|
100 | errors = [ | |
99 | validation_schema.Invalid(node, search_result['error'])] |
|
101 | validation_schema.Invalid(node, search_result['error'])] | |
100 |
|
102 | |||
|
103 | c.sort = search_sort | |||
|
104 | c.url_generator = url_generator | |||
101 | c.errors = errors |
|
105 | c.errors = errors | |
102 | c.formatted_results = formatted_results |
|
106 | c.formatted_results = formatted_results | |
103 | c.runtime = execution_time |
|
107 | c.runtime = execution_time |
@@ -100,7 +100,7 b' class Search(BaseSearch):' | |||||
100 | return query |
|
100 | return query | |
101 |
|
101 | |||
102 | def search(self, query, document_type, search_user, repo_name=None, |
|
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 | original_query = query |
|
105 | original_query = query | |
106 | query = self._extend_query(query) |
|
106 | query = self._extend_query(query) | |
@@ -123,13 +123,18 b' class Search(BaseSearch):' | |||||
123 | query = qp.parse(unicode(query)) |
|
123 | query = qp.parse(unicode(query)) | |
124 | log.debug('query: %s (%s)' % (query, repr(query))) |
|
124 | log.debug('query: %s (%s)' % (query, repr(query))) | |
125 |
|
125 | |||
126 | sortedby = None |
|
126 | reverse, sortedby = False, None | |
127 | if search_type == 'message': |
|
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 | whoosh_results = self.searcher.search( |
|
135 | whoosh_results = self.searcher.search( | |
131 | query, filter=allowed_repos_filter, limit=None, |
|
136 | query, filter=allowed_repos_filter, limit=None, | |
132 | sortedby=sortedby,) |
|
137 | sortedby=sortedby, reverse=reverse) | |
133 |
|
138 | |||
134 | # fixes for 32k limit that whoosh uses for highlight |
|
139 | # fixes for 32k limit that whoosh uses for highlight | |
135 | whoosh_results.fragmenter.charlimit = None |
|
140 | whoosh_results.fragmenter.charlimit = None |
@@ -51,6 +51,11 b' class SearchParamsSchema(colander.Mappin' | |||||
51 | colander.String(), |
|
51 | colander.String(), | |
52 | missing='content', |
|
52 | missing='content', | |
53 | validator=colander.OneOf(['content', 'path', 'commit', 'repository'])) |
|
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 | page_limit = colander.SchemaNode( |
|
59 | page_limit = colander.SchemaNode( | |
55 | colander.Integer(), |
|
60 | colander.Integer(), | |
56 | missing=10, |
|
61 | missing=10, |
@@ -6,7 +6,13 b'' | |||||
6 | <th>${_('Commit')}</th> |
|
6 | <th>${_('Commit')}</th> | |
7 | <th></th> |
|
7 | <th></th> | |
8 | <th>${_('Commit message')}</th> |
|
8 | <th>${_('Commit message')}</th> | |
9 |
<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 | <th>${_('Author')}</th> |
|
16 | <th>${_('Author')}</th> | |
11 | </tr> |
|
17 | </tr> | |
12 | %for entry in c.formatted_results: |
|
18 | %for entry in c.formatted_results: |
General Comments 0
You need to be logged in to leave comments.
Login now