You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/03/26 22:13:52 UTC
[5/7] git commit: [#2835] ticket:289 Sort search results
[#2835] ticket:289 Sort search results
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/1b383828
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/1b383828
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/1b383828
Branch: refs/heads/db/42cc_2835_content_preview
Commit: 1b383828cd344b8987dbe7c650e931a7d0fda405
Parents: 3a8d150
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Mar 19 12:21:09 2013 +0000
Committer: Dave Brondsema <db...@geek.net>
Committed: Tue Mar 26 21:13:22 2013 +0000
----------------------------------------------------------------------
Allura/allura/lib/widgets/resources/css/search.css | 4 ++
.../allura/templates/widgets/search_results.html | 7 +++-
ForgeWiki/forgewiki/templates/wiki/search.html | 3 +-
ForgeWiki/forgewiki/wiki_main.py | 24 +++++++++++++-
4 files changed, 33 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1b383828/Allura/allura/lib/widgets/resources/css/search.css
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/css/search.css b/Allura/allura/lib/widgets/resources/css/search.css
index 46361df..7994bc5 100644
--- a/Allura/allura/lib/widgets/resources/css/search.css
+++ b/Allura/allura/lib/widgets/resources/css/search.css
@@ -18,3 +18,7 @@ input[type="checkbox"] {
width: 100%;
white-space: nowrap;
}
+
+.strong {
+ font-weight: bold;
+}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1b383828/Allura/allura/templates/widgets/search_results.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/search_results.html b/Allura/allura/templates/widgets/search_results.html
index f649b14..1401f0c 100644
--- a/Allura/allura/templates/widgets/search_results.html
+++ b/Allura/allura/templates/widgets/search_results.html
@@ -61,6 +61,9 @@
{{widget.fields['page_size'].display(limit=limit, count=count)}}
</div>
<div class="grid-19" style="clear:both">
- {# TODO: highlight active sorting order #}
- {# <p>Sort by <a href="#"><strong>relevance</strong></a> or <a href="#">date</a></p> #}
+ <p>
+ Sort by
+ <a href="{{ sort_score_url }}" class="{{ 'strong' if sort_field == 'score' else '' }}">relevance</a> or
+ <a href="{{ sort_date_url }}" class="{{ 'strong' if sort_field == 'mod_date_dt' else '' }}">date</a>
+ </p>
</div>
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1b383828/ForgeWiki/forgewiki/templates/wiki/search.html
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/templates/wiki/search.html b/ForgeWiki/forgewiki/templates/wiki/search.html
index 0441d3e..9680aea 100644
--- a/ForgeWiki/forgewiki/templates/wiki/search.html
+++ b/ForgeWiki/forgewiki/templates/wiki/search.html
@@ -6,5 +6,6 @@
{% block wiki_content %}
{{c.search_results.display(results=results,q=q,history=history,
- count=count,limit=limit,page=page,search_error=search_error)}}
+ count=count,limit=limit,page=page,search_error=search_error,
+ sort_score_url=sort_score_url, sort_date_url=sort_date_url, sort_field=sort_field)}}
{% endblock %}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1b383828/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index 2ac42f6..f978970 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -6,7 +6,7 @@ from datetime import datetime
from itertools import imap
# Non-stdlib imports
-from tg import expose, validate, redirect, response, flash
+from tg import expose, validate, redirect, response, flash, url
from tg.decorators import with_trailing_slash, without_trailing_slash
from tg.controllers import RestController
from pylons import tmpl_context as c, app_globals as g
@@ -303,6 +303,7 @@ class RootController(BaseController, DispatchIndex):
results = []
count = 0
parser = kw.pop('parser', None)
+ sort = kw.pop('sort', 'score desc')
matches = {}
limit, page, start = g.handle_paging(limit, page, default=25)
if not q:
@@ -327,6 +328,7 @@ class RootController(BaseController, DispatchIndex):
'hl': 'true',
'hl.simple.pre': '<strong>',
'hl.simple.post': '</strong>',
+ 'sort': sort,
}
if not history:
search_params['fq'].append('is_history_b:False')
@@ -358,8 +360,26 @@ class RootController(BaseController, DispatchIndex):
results = imap(historize_urls, results)
results = imap(add_matches, results)
c.search_results = W.search_results
+ score_url = 'score desc'
+ date_url = 'mod_date_dt desc'
+ try:
+ field, order = sort.split(' ')
+ except ValueError:
+ field, order = 'score', 'desc'
+ sort = ' '.join([field, 'asc' if order == 'desc' else 'desc'])
+ if field == 'score':
+ score_url = sort
+ elif field == 'mod_date_dt':
+ date_url = sort
+ params = request.GET.copy()
+ params.update({'sort': score_url})
+ score_url = url(request.path, params=params)
+ params.update({'sort': date_url})
+ date_url = url(request.path, params=params)
return dict(q=q, history=history, results=results or [],
- count=count, limit=limit, page=page, search_error=search_error)
+ count=count, limit=limit, page=page, search_error=search_error,
+ sort_score_url=score_url, sort_date_url=date_url,
+ sort_field=field)
@with_trailing_slash
@expose('jinja:forgewiki:templates/wiki/browse.html')