diff --git a/rhodecode/controllers/search.py b/rhodecode/controllers/search.py --- a/rhodecode/controllers/search.py +++ b/rhodecode/controllers/search.py @@ -56,23 +56,25 @@ class SearchController(BaseRepoControlle search_params = schema.deserialize( dict(search_query=request.GET.get('q'), search_type=request.GET.get('type'), + search_sort=request.GET.get('sort'), page_limit=request.GET.get('page_limit'), requested_page=request.GET.get('page')) ) except validation_schema.Invalid as e: errors = e.children + def url_generator(**kw): + q = urllib.quote(safe_str(search_query)) + return update_params( + "?q=%s&type=%s" % (q, safe_str(search_type)), **kw) + search_query = search_params.get('search_query') search_type = search_params.get('search_type') - + search_sort = search_params.get('search_sort') if search_params.get('search_query'): page_limit = search_params['page_limit'] requested_page = search_params['requested_page'] - def url_generator(**kw): - q = urllib.quote(safe_str(search_query)) - return update_params( - "?q=%s&type=%s" % (q, safe_str(search_type)), **kw) c.perm_user = AuthUser(user_id=c.rhodecode_user.user_id, ip_addr=self.ip_addr) @@ -80,7 +82,7 @@ class SearchController(BaseRepoControlle try: search_result = searcher.search( search_query, search_type, c.perm_user, repo_name, - requested_page, page_limit) + requested_page, page_limit, search_sort) formatted_results = Page( search_result['results'], page=requested_page, @@ -98,6 +100,8 @@ class SearchController(BaseRepoControlle errors = [ validation_schema.Invalid(node, search_result['error'])] + c.sort = search_sort + c.url_generator = url_generator c.errors = errors c.formatted_results = formatted_results c.runtime = execution_time diff --git a/rhodecode/lib/index/whoosh.py b/rhodecode/lib/index/whoosh.py --- a/rhodecode/lib/index/whoosh.py +++ b/rhodecode/lib/index/whoosh.py @@ -100,7 +100,7 @@ class Search(BaseSearch): return query def search(self, query, document_type, search_user, repo_name=None, - requested_page=1, page_limit=10): + requested_page=1, page_limit=10, sort=None): original_query = query query = self._extend_query(query) @@ -123,13 +123,18 @@ class Search(BaseSearch): query = qp.parse(unicode(query)) log.debug('query: %s (%s)' % (query, repr(query))) - sortedby = None + reverse, sortedby = False, None if search_type == 'message': - sortedby = sorting.FieldFacet('commit_idx', reverse=True) + if sort == 'oldfirst': + sortedby = 'date' + reverse = False + elif sort == 'newfirst': + sortedby = 'date' + reverse = True whoosh_results = self.searcher.search( query, filter=allowed_repos_filter, limit=None, - sortedby=sortedby,) + sortedby=sortedby, reverse=reverse) # fixes for 32k limit that whoosh uses for highlight whoosh_results.fragmenter.charlimit = None diff --git a/rhodecode/model/validation_schema.py b/rhodecode/model/validation_schema.py --- a/rhodecode/model/validation_schema.py +++ b/rhodecode/model/validation_schema.py @@ -51,6 +51,11 @@ class SearchParamsSchema(colander.Mappin colander.String(), missing='content', validator=colander.OneOf(['content', 'path', 'commit', 'repository'])) + search_sort = colander.SchemaNode( + colander.String(), + missing='newfirst', + validator=colander.OneOf( + ['oldfirst', 'newfirst'])) page_limit = colander.SchemaNode( colander.Integer(), missing=10, diff --git a/rhodecode/templates/search/search_commit.html b/rhodecode/templates/search/search_commit.html --- a/rhodecode/templates/search/search_commit.html +++ b/rhodecode/templates/search/search_commit.html @@ -6,7 +6,13 @@