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

[1/7] git commit: [#2835] ticket:290 Make solr's field stored

Updated Branches:
  refs/heads/db/42cc_2835_content_preview [created] bcc5f812a


[#2835] ticket:290 Make solr's  field stored


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/802c426a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/802c426a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/802c426a

Branch: refs/heads/db/42cc_2835_content_preview
Commit: 802c426a1c729fcf2f7bbc6d23229ce9dacfdab3
Parents: aced859
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Mar 12 12:36:08 2013 +0000
Committer: Dave Brondsema <db...@geek.net>
Committed: Tue Mar 26 21:05:16 2013 +0000

----------------------------------------------------------------------
 solr_config/core0/conf/schema.xml |    2 +-
 solr_config/core1/conf/schema.xml |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/802c426a/solr_config/core0/conf/schema.xml
----------------------------------------------------------------------
diff --git a/solr_config/core0/conf/schema.xml b/solr_config/core0/conf/schema.xml
index 494f53f..e2e0d79 100644
--- a/solr_config/core0/conf/schema.xml
+++ b/solr_config/core0/conf/schema.xml
@@ -428,7 +428,7 @@
 
    <!-- catchall field, containing all other searchable text fields (implemented
         via copyField further on in this schema  -->
-   <field name="text" type="text" indexed="true" stored="false" multiValued="true"/>
+   <field name="text" type="text" indexed="true" stored="true" multiValued="true"/>
 
    <!-- catchall text field that indexes tokens both normally and in reverse for efficient
         leading wildcard queries. -->

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/802c426a/solr_config/core1/conf/schema.xml
----------------------------------------------------------------------
diff --git a/solr_config/core1/conf/schema.xml b/solr_config/core1/conf/schema.xml
index 494f53f..e2e0d79 100644
--- a/solr_config/core1/conf/schema.xml
+++ b/solr_config/core1/conf/schema.xml
@@ -428,7 +428,7 @@
 
    <!-- catchall field, containing all other searchable text fields (implemented
         via copyField further on in this schema  -->
-   <field name="text" type="text" indexed="true" stored="false" multiValued="true"/>
+   <field name="text" type="text" indexed="true" stored="true" multiValued="true"/>
 
    <!-- catchall text field that indexes tokens both normally and in reverse for efficient
         leading wildcard queries. -->


[5/7] git commit: [#2835] ticket:289 Sort search results

Posted by br...@apache.org.
[#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')


[7/7] git commit: [#2835] ticket:291 Search help button

Posted by br...@apache.org.
[#2835] ticket:291 Search help button


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/bcc5f812
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/bcc5f812
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/bcc5f812

Branch: refs/heads/db/42cc_2835_content_preview
Commit: bcc5f812a3958a1697d3a16d81e9a16f1fc63114
Parents: 218f4b4
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Mar 21 13:47:55 2013 +0000
Committer: Dave Brondsema <db...@geek.net>
Committed: Tue Mar 26 21:13:22 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/widgets/search.py                |   13 +++++++++++++
 .../allura/templates/widgets/search_results.html   |    5 +++--
 ForgeWiki/forgewiki/templates/wiki/search_help.txt |    8 ++++++++
 ForgeWiki/forgewiki/tests/functional/test_root.py  |    8 ++++++++
 ForgeWiki/forgewiki/wiki_main.py                   |    9 ++++++++-
 5 files changed, 40 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bcc5f812/Allura/allura/lib/widgets/search.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/search.py b/Allura/allura/lib/widgets/search.py
index fc17b3e..7426e5f 100644
--- a/Allura/allura/lib/widgets/search.py
+++ b/Allura/allura/lib/widgets/search.py
@@ -22,3 +22,16 @@ class SearchResults(ew_core.Widget):
             for r in f.resources():
                 yield r
         yield ew.CSSLink('css/search.css')
+
+
+class SearchHelp(ffw.Lightbox):
+    defaults=dict(
+        ffw.Lightbox.defaults,
+        name='search_help_modal',
+        trigger='a.search_help_modal')
+
+    content_template = '<div style="height:400px; overflow:auto;">%s</div>'
+
+    def __init__(self, content=''):
+        super(SearchHelp, self).__init__()
+        self.content = self.content_template % content

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bcc5f812/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 1401f0c..5e906e2 100644
--- a/Allura/allura/templates/widgets/search_results.html
+++ b/Allura/allura/templates/widgets/search_results.html
@@ -5,14 +5,14 @@
   <div class="grid-3">
     <input type="submit" value="Search">
   </div>
+  {% if c.help_modal %}
   <div class="grid-6">
-    {# TODO: when help text provided, show button
     <a href="#" class="btn search_help_modal">
       <b data-icon="{{g.icons['help'].char}}" class="ico {{g.icons['help'].css}}"></b>
       Help
     </a>
-    #}
   </div>
+  {% endif %}
   <div class="grid-10">
     {% set search_project = request.GET['project'] == '1' %}
     <input type="radio" name="project" value="0" id="search-app" {% if not search_project %}checked{% endif %}>
@@ -67,3 +67,4 @@
     <a href="{{ sort_date_url }}" class="{{ 'strong' if sort_field == 'mod_date_dt' else '' }}">date</a>
   </p>
 </div>
+{% if c.help_modal %}{{ c.help_modal.display() }}{% endif %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bcc5f812/ForgeWiki/forgewiki/templates/wiki/search_help.txt
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/templates/wiki/search_help.txt b/ForgeWiki/forgewiki/templates/wiki/search_help.txt
new file mode 100644
index 0000000..4a337b8
--- /dev/null
+++ b/ForgeWiki/forgewiki/templates/wiki/search_help.txt
@@ -0,0 +1,8 @@
+<h1>Searching wiki</h1>
+<p>Searches use wiki page title and inner text for matching.<p>
+<p>You can also use 'Search comments?' and 'Search history?' checkboxes to include comments and history of pages editing in the search results.</p>
+
+<p>If you want to see all the page with given label, you may use url like this (there is no UI for this):</p>
+<div class="codehilite">
+<pre>/p/yourproject/wiki/search/?q=labels_t:label&amp;parser=standard</pre>
+</div>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bcc5f812/ForgeWiki/forgewiki/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/functional/test_root.py b/ForgeWiki/forgewiki/tests/functional/test_root.py
index be4185d..3dcc1bc 100644
--- a/ForgeWiki/forgewiki/tests/functional/test_root.py
+++ b/ForgeWiki/forgewiki/tests/functional/test_root.py
@@ -107,6 +107,14 @@ class TestRootController(TestController):
         solr_query.pop('pf')
         search.assert_called_with('test', **solr_query)
 
+    def test_search_help(self):
+        r = self.app.get('/wiki/search?q=test')
+        btn = r.html.find('a', attrs={'class': 'btn search_help_modal'})
+        assert btn is not None, "Can't find a help button"
+        div = r.html.find('div', attrs={'id': 'lightbox_search_help_modal'})
+        assert div is not None, "Can't find help text"
+        assert_in('Searching wiki', div.text)
+
     def test_page_index(self):
         response = self.app.get('/wiki/tést/')
         assert 'tést' in response.follow()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bcc5f812/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index f978970..ac6667f 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -14,6 +14,7 @@ from pylons import request
 from formencode import validators
 from webob import exc
 from ming.orm import session
+import jinja2
 
 # Pyforge-specific imports
 from allura import model as M
@@ -28,7 +29,7 @@ from allura.controllers import attachments as ac
 from allura.lib import widgets as w
 from allura.lib.widgets import form_fields as ffw
 from allura.lib.widgets.subscriptions import SubscribeForm
-from allura.lib.widgets.search import SearchResults
+from allura.lib.widgets.search import SearchResults, SearchHelp
 
 # Local imports
 from forgewiki import model as WM
@@ -37,6 +38,10 @@ from forgewiki.widgets.wiki import CreatePageWidget
 
 log = logging.getLogger(__name__)
 
+jinja_env = jinja2.Environment(loader=jinja2.PackageLoader('forgewiki', 'templates'))
+search_help_text = jinja_env.get_template('wiki/search_help.txt').render()
+
+
 class W:
     thread=w.Thread(
         page=None, limit=None, page_size=None, count=None,
@@ -51,6 +56,7 @@ class W:
     page_list = ffw.PageList()
     page_size = ffw.PageSize()
     search_results = SearchResults()
+    help_modal = SearchHelp(search_help_text)
     icons={
         24:'images/wiki_24.png',
         32:'images/wiki_32.png',
@@ -360,6 +366,7 @@ class RootController(BaseController, DispatchIndex):
                 results = imap(historize_urls, results)
                 results = imap(add_matches, results)
         c.search_results = W.search_results
+        c.help_modal = W.help_modal
         score_url = 'score desc'
         date_url = 'mod_date_dt desc'
         try:


[6/7] git commit: [#2835] ticket:289 Test wiki search

Posted by br...@apache.org.
[#2835] ticket:289 Test wiki search


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/218f4b4c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/218f4b4c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/218f4b4c

Branch: refs/heads/db/42cc_2835_content_preview
Commit: 218f4b4c5277d2c0f61901e61b71f06722c3b675
Parents: 1b38382
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Mar 19 13:02:45 2013 +0000
Committer: Dave Brondsema <db...@geek.net>
Committed: Tue Mar 26 21:13:22 2013 +0000

----------------------------------------------------------------------
 ForgeWiki/forgewiki/tests/functional/test_root.py |   47 +++++++++++++++-
 1 files changed, 46 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/218f4b4c/ForgeWiki/forgewiki/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/functional/test_root.py b/ForgeWiki/forgewiki/tests/functional/test_root.py
index 7c98499..be4185d 100644
--- a/ForgeWiki/forgewiki/tests/functional/test_root.py
+++ b/ForgeWiki/forgewiki/tests/functional/test_root.py
@@ -3,7 +3,7 @@ import os
 import Image, StringIO
 import allura
 
-from nose.tools import assert_true, assert_equal
+from nose.tools import assert_true, assert_equal, assert_in
 
 from ming.orm.ormsession import ThreadLocalORMSession
 from mock import patch
@@ -62,6 +62,51 @@ class TestRootController(TestController):
         response = self.app.get('/wiki/search?q=tést')
         assert 'Search wiki: tést' in response
 
+    @patch('forgewiki.wiki_main.search')
+    def test_search(self, search):
+        r = self.app.get('/wiki/search?q=test')
+        assert_in('<a href="/wiki/search?q=test&amp;sort=score+asc" class="strong">relevance</a>', r)
+        assert_in('<a href="/wiki/search?q=test&amp;sort=mod_date_dt+desc" class="">date</a>', r)
+
+        p = M.Project.query.get(shortname='test')
+        r = self.app.get('/wiki/search?q=test&sort=score+asc')
+        solr_query = {
+            'short_timeout': True,
+            'ignore_errors': False,
+            'rows': 25,
+            'start': 0,
+            'qt': 'dismax',
+            'qf': 'title^2 text',
+            'pf': 'title^2 text',
+            'fq': [
+                'project_id_s:%s'  % p._id,
+                'mount_point_s:wiki',
+                '-deleted_b:true',
+                'type_s:("WikiPage" OR "WikiPage Snapshot")',
+                'is_history_b:False',
+            ],
+            'hl': 'true',
+            'hl.simple.pre': '<strong>',
+            'hl.simple.post': '</strong>',
+            'sort': 'score asc',
+        }
+        search.assert_called_with('test', **solr_query)
+
+        r = self.app.get('/wiki/search?q=test&search_comments=on&history=on&sort=mod_date_dt+desc')
+        solr_query['fq'][3] = 'type_s:("WikiPage" OR "WikiPage Snapshot" OR "Post")'
+        solr_query['fq'].remove('is_history_b:False')
+        solr_query['sort'] = 'mod_date_dt desc'
+        search.assert_called_with('test', **solr_query)
+
+        r = self.app.get('/wiki/search?q=test&parser=standard')
+        solr_query['sort'] = 'score desc'
+        solr_query['fq'][3] = 'type_s:("WikiPage" OR "WikiPage Snapshot")'
+        solr_query['fq'].append('is_history_b:False')
+        solr_query.pop('qt')
+        solr_query.pop('qf')
+        solr_query.pop('pf')
+        search.assert_called_with('test', **solr_query)
+
     def test_page_index(self):
         response = self.app.get('/wiki/tést/')
         assert 'tést' in response.follow()


[3/7] git commit: [#2835] ticket:290 Convert markdown to plain text before indexation

Posted by br...@apache.org.
[#2835] ticket:290 Convert markdown to plain text before indexation


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/ec1db8d5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/ec1db8d5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/ec1db8d5

Branch: refs/heads/db/42cc_2835_content_preview
Commit: ec1db8d56ccde9917b159ef91921f8e1f974808b
Parents: ecc187a
Author: Igor Bondarenko <je...@gmail.com>
Authored: Wed Mar 13 13:22:40 2013 +0000
Committer: Dave Brondsema <db...@geek.net>
Committed: Tue Mar 26 21:10:36 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/search.py |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ec1db8d5/Allura/allura/lib/search.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/search.py b/Allura/allura/lib/search.py
index a428c53..43a4c85 100644
--- a/Allura/allura/lib/search.py
+++ b/Allura/allura/lib/search.py
@@ -3,6 +3,7 @@ import socket
 from logging import getLogger
 
 import markdown
+import jinja2
 from pylons import tmpl_context as c, app_globals as g
 from pysolr import SolrError
 
@@ -17,6 +18,11 @@ def solarize(obj):
     # if index() returned doc without text, assume empty text
     if not doc.get('text'):
         doc['text'] = ''
+    # Convert text to plain text (It usually contains markdown markup).
+    # To do so, we convert markdown into html, and then strip all html tags.
+    text = doc['text']
+    text = g.markdown.convert(text)
+    doc['text'] = jinja2.Markup.escape(text).striptags()
     return doc
 
 class SearchError(SolrError):


[4/7] git commit: [#2835] ticket:290 Use get_first helper and fix title displaying

Posted by br...@apache.org.
[#2835] ticket:290 Use get_first helper and fix title displaying


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/3a8d150e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/3a8d150e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/3a8d150e

Branch: refs/heads/db/42cc_2835_content_preview
Commit: 3a8d150edb73cb2e61e6a856236b8388d19573d5
Parents: ec1db8d
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Mar 19 10:42:34 2013 +0000
Committer: Dave Brondsema <db...@geek.net>
Committed: Tue Mar 26 21:13:20 2013 +0000

----------------------------------------------------------------------
 .../allura/templates/widgets/search_results.html   |    6 +++++-
 ForgeWiki/forgewiki/wiki_main.py                   |    6 +++---
 2 files changed, 8 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3a8d150e/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 ba7bf9d..f649b14 100644
--- a/Allura/allura/templates/widgets/search_results.html
+++ b/Allura/allura/templates/widgets/search_results.html
@@ -41,7 +41,11 @@
   <div class="grid-19">
     <p>
     <a href="{{doc['url_paginated'] or doc['url_s']}}">
-       {{- doc.title_match|safe or h.get_first(doc, 'title') or h.get_first(doc, 'title_s') -}}  {#-  title_s is legacy -#}
+      {% if doc.title_match %}
+        {{ doc.title_match|safe }}
+      {% else %}
+        {{ h.get_first(doc, 'title') or h.get_first(doc, 'title_s') -}}  {#-  title_s is legacy -#}
+      {% endif %}
     </a>
     {% if doc['type_s'] %}<span class="gray"><sup>{{ '(%s)' % doc['type_s'] }}</sup></span>{% endif %}
     <br>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3a8d150e/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index d292c91..2ac42f6 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -350,10 +350,10 @@ class RootController(BaseController, DispatchIndex):
                     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]
+                    doc['title_match'] = h.get_first(m, 'title')
+                    doc['text_match'] = h.get_first(m, 'text')
                     if not doc['text_match']:
-                        doc['text_match'] = doc.get('text', [''])[0]
+                        doc['text_match'] = h.get_first(doc, 'text')
                     return doc
                 results = imap(historize_urls, results)
                 results = imap(add_matches, results)


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

Posted by br...@apache.org.
[#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)