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:49 UTC

[2/7] git commit: [#2835] ticket:290 Show content preview with highlighted matches on wiki search results

[#2835] ticket:290 Show content preview with highlighted matches on wiki 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/ecc187a9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/ecc187a9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/ecc187a9

Branch: refs/heads/db/42cc_2835_content_preview
Commit: ecc187a9d58bdce589bd27fa7b09864e5a5686b7
Parents: 802c426
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Mar 12 13:23:45 2013 +0000
Committer: Dave Brondsema <db...@geek.net>
Committed: Tue Mar 26 21:10:34 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/widgets/resources/css/search.css |    8 ++++++++
 .../allura/templates/widgets/search_results.html   |    7 ++++---
 ForgeWiki/forgewiki/wiki_main.py                   |   15 ++++++++++++++-
 3 files changed, 26 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ecc187a9/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 f687399..46361df 100644
--- a/Allura/allura/lib/widgets/resources/css/search.css
+++ b/Allura/allura/lib/widgets/resources/css/search.css
@@ -10,3 +10,11 @@ input[type="radio"],
 input[type="checkbox"] {
   vertical-align: middle;
 }
+
+.text-match {
+  overflow: hidden;
+  text-overflow: ellipsis;
+  display: inline-block;
+  width: 100%;
+  white-space: nowrap;
+}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ecc187a9/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 b586dec..ba7bf9d 100644
--- a/Allura/allura/templates/widgets/search_results.html
+++ b/Allura/allura/templates/widgets/search_results.html
@@ -39,14 +39,15 @@
 </div>
 {% for doc in results %}
   <div class="grid-19">
-    {# TODO: mark matches in title and snippet #}
     <p>
     <a href="{{doc['url_paginated'] or doc['url_s']}}">
-       {{- h.get_first(doc, 'title') or h.get_first(doc, 'title_s') -}}  {#-  title_s is legacy -#}
+       {{- doc.title_match|safe or h.get_first(doc, 'title') or h.get_first(doc, 'title_s') -}}  {#-  title_s is legacy -#}
     </a>
     {% if doc['type_s'] %}<span class="gray"><sup>{{ '(%s)' % doc['type_s'] }}</sup></span>{% endif %}
     <br>
-    {{ doc.snippet }}
+    {% if doc.text_match %}
+      <span class="text-match">{{ doc.text_match|safe }}</span><br>
+    {% endif %}
     <span class="gray">Last updated: {{ h.ago_string(doc['mod_date_dt']) }}</span>
     </p>
   </div>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ecc187a9/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index be11731..d292c91 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -303,6 +303,7 @@ class RootController(BaseController, DispatchIndex):
         results = []
         count = 0
         parser = kw.pop('parser', None)
+        matches = {}
         limit, page, start = g.handle_paging(limit, page, default=25)
         if not q:
             q = ''
@@ -323,6 +324,9 @@ class RootController(BaseController, DispatchIndex):
                     '-deleted_b:true',
                     'type_s:(%s)' % ' OR '.join(['"%s"' % t for t in allowed_types])
                 ],
+                'hl': 'true',
+                'hl.simple.pre': '<strong>',
+                'hl.simple.post': '</strong>',
             }
             if not history:
                search_params['fq'].append('is_history_b:False')
@@ -337,13 +341,22 @@ class RootController(BaseController, DispatchIndex):
             except SolrError as e:
                 search_error = e
             if results:
-                count=results.hits
+                count = results.hits
+                matches = results.highlighting
                 def historize_urls(doc):
                     if doc.get('type_s', '').endswith(' Snapshot'):
                         if doc.get('url_s'):
                             doc['url_s'] = doc['url_s'] + '?version=%s' % doc.get('version_i')
                     return doc
+                def add_matches(doc):
+                    m = matches.get(doc['id'], {})
+                    doc['title_match'] = m.get('title', [''])[0]
+                    doc['text_match'] = m.get('text', [''])[0]
+                    if not doc['text_match']:
+                        doc['text_match'] = doc.get('text', [''])[0]
+                    return doc
                 results = imap(historize_urls, results)
+                results = imap(add_matches, results)
         c.search_results = W.search_results
         return dict(q=q, history=history, results=results or [],
                     count=count, limit=limit, page=page, search_error=search_error)