You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/04/25 00:30:42 UTC

[17/50] 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/1ec5943b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/1ec5943b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/1ec5943b

Branch: refs/heads/cj/5655
Commit: 1ec5943b5e1f0b9c55ea3529fe31d849d76adcf5
Parents: 0d09236
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Mar 19 12:21:09 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Apr 24 16:34:40 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/1ec5943b/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 848accc..03b5507 100644
--- a/Allura/allura/lib/widgets/resources/css/search.css
+++ b/Allura/allura/lib/widgets/resources/css/search.css
@@ -36,3 +36,7 @@ input[type="checkbox"] {
   width: 100%;
   white-space: nowrap;
 }
+
+.strong {
+  font-weight: bold;
+}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1ec5943b/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 7eb577d..feaa60f 100644
--- a/Allura/allura/templates/widgets/search_results.html
+++ b/Allura/allura/templates/widgets/search_results.html
@@ -79,6 +79,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/1ec5943b/ForgeWiki/forgewiki/templates/wiki/search.html
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/templates/wiki/search.html b/ForgeWiki/forgewiki/templates/wiki/search.html
index 6c91664..6f7085e 100644
--- a/ForgeWiki/forgewiki/templates/wiki/search.html
+++ b/ForgeWiki/forgewiki/templates/wiki/search.html
@@ -24,5 +24,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/1ec5943b/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index 4a47b3b..fc5b566 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -23,7 +23,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
@@ -320,6 +320,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:
@@ -344,6 +345,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')
@@ -375,8 +377,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')