incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [26/50] git commit: [#2835] ticket:292 Better search for discussion
Date Wed, 24 Apr 2013 22:30:51 GMT
[#2835] ticket:292 Better search for discussion


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

Branch: refs/heads/cj/5655
Commit: 91e308c6375731f5d61dc64fb462fa2156870a8a
Parents: b636c9d
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Mar 25 12:54:06 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Apr 24 16:34:41 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/artifact.py                    |    4 +-
 Allura/allura/model/discuss.py                     |    4 +-
 .../forgediscussion/controllers/root.py            |   62 ++++++---------
 .../templates/discussionforums/search.html         |    4 +-
 4 files changed, 33 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/91e308c6/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 49109c7..681ac26 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -332,8 +332,8 @@ class Snapshot(Artifact):
         if original:
             original_index = original.index()
             result.update(original_index)
-            result['title'] = 'Version %d of %s' % (
-                    self.version, h.get_first(original_index, 'title'))
+            result['title'] = '%s (version %d)' % (
+                    h.get_first(original_index, 'title'), self.version)
         result.update(
             id=self.index_id(),
             version_i=self.version,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/91e308c6/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index 76a9aa1..e3cf591 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -107,7 +107,7 @@ class Discussion(Artifact, ActivityObject):
     def index(self):
         result = Artifact.index(self)
         result.update(
-            title='Discussion: %s' % self.name,
+            title=self.name,
             name_s=self.name,
             text=self.description)
         return result
@@ -356,7 +356,7 @@ class Thread(Artifact, ActivityObject):
     def index(self):
         result = Artifact.index(self)
         result.update(
-           title='Thread: %s' % (self.subject or '(no subject)'),
+           title=self.subject or '(no subject)',
            name_s=self.subject,
            views_i=self.num_views,
            text=self.subject)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/91e308c6/ForgeDiscussion/forgediscussion/controllers/root.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/controllers/root.py b/ForgeDiscussion/forgediscussion/controllers/root.py
index cce0090..f5f4ae5 100644
--- a/ForgeDiscussion/forgediscussion/controllers/root.py
+++ b/ForgeDiscussion/forgediscussion/controllers/root.py
@@ -15,11 +15,10 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
-import re
 import json
 import logging
-import pymongo
-from urllib import urlencode, unquote
+from urllib import unquote
+from itertools import imap
 
 from tg import expose, validate, redirect, flash, response
 from tg.decorators import with_trailing_slash
@@ -31,7 +30,7 @@ from webob import exc
 
 from allura.lib.security import require_access, has_access, require_authenticated
 from allura.model import Feed
-from allura.lib.search import search, SearchError
+from allura.lib.search import search_app
 from allura.lib import helpers as h
 from allura.lib.utils import AntiSpam
 from allura.lib.decorators import require_post
@@ -130,40 +129,31 @@ class RootController(BaseController, DispatchIndex):
                    project=validators.StringBool(if_empty=False),
                    limit=validators.Int(if_empty=None),
                    page=validators.Int(if_empty=0)))
-    def search(self, q=None, history=False, project=False, limit=None, page=0, **kw):
-        'local tool search'
-        if project:
-            redirect(c.project.url() + 'search?' + urlencode(dict(q=q, history=history)))
-        results = []
-        search_error = None
-        count=0
-        limit, page, start = g.handle_paging(limit, page, default=25)
-        if not q:
-            q = ''
-        else:
-            try:
-                results = search(
-                    q, rows=limit, start=start,
-                    fq=[
-                        'is_history_b:%s' % history,
-                        'project_id_s:%s' % c.project._id,
-                        'mount_point_s:%s'% c.app.config.options.mount_point,
-                        '-deleted_b:true'],
-                    short_timeout=True,
-                    ignore_errors=False)
-            except SearchError as e:
-                search_error = e
-            if results: count=results.hits
+    def search(self, q=None, history=None, project=None, limit=None, page=0, **kw):
         c.search_results = self.W.search_results
+        search_params = kw
+        search_params.update({
+            'q': q or '',
+            'history': history,
+            'project': project,
+            'limit': limit,
+            'page': page,
+            'allowed_types': ['Post', 'Post Snapshot', 'Discussion', 'Thread'],
+        })
+        d = search_app(**search_params)
+        results = d.get('results')
+        def prettify_urls(doc):
+            if doc.get('type_s', '') == 'Post':
+                _id = doc.get('id').split('#')
+                _id = _id[-1].replace('/', '.') if _id else ''
+                p = model.ForumPost.query.get(_id=_id)
+                doc['url_paginated'] = p.url_paginated()
+            return doc
         if results is not None:
-            for doc in results:
-                if doc.get('type_s', '') == 'Post':
-                    _id = doc.get('id').split('#')
-                    _id = _id[-1].replace('/', '.') if _id else ''
-                    p = model.ForumPost.query.get(_id=_id)
-                    doc['url_paginated'] = p.url_paginated()
-        return dict(q=q, history=history, results=results or [],
-                    count=count, limit=limit, page=page, search_error=search_error)
+            results = imap(prettify_urls, results)
+        d['results'] = results
+        d['search_comments_disable'] = True
+        return d
 
     @expose('jinja:allura:templates/markdown_syntax.html')
     def markdown_syntax(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/91e308c6/ForgeDiscussion/forgediscussion/templates/discussionforums/search.html
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/templates/discussionforums/search.html b/ForgeDiscussion/forgediscussion/templates/discussionforums/search.html
index 4c549cd..0fdb640 100644
--- a/ForgeDiscussion/forgediscussion/templates/discussionforums/search.html
+++ b/ForgeDiscussion/forgediscussion/templates/discussionforums/search.html
@@ -24,5 +24,7 @@
 
 {% block 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,
+     search_comments_disable=search_comments_disable)}}
 {% endblock %}


Mime
View raw message