allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [09/28] git commit: [#2835] ticket:292 Better blog search
Date Wed, 24 Apr 2013 17:16:18 GMT
[#2835] ticket:292 Better blog 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/b636c9d2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/b636c9d2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/b636c9d2

Branch: refs/heads/db/2835
Commit: b636c9d2a5ec36d469b6743e19a9241c5d14857e
Parents: 891ff45
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Mar 25 12:31:07 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Apr 24 16:34:41 2013 +0000

----------------------------------------------------------------------
 ForgeBlog/forgeblog/main.py                    |   48 +++++++++----------
 ForgeBlog/forgeblog/model/blog.py              |    5 +-
 ForgeBlog/forgeblog/templates/blog/search.html |   27 ++---------
 3 files changed, 28 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b636c9d2/ForgeBlog/forgeblog/main.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/main.py b/ForgeBlog/forgeblog/main.py
index 65f5c6d..91ed6b6 100644
--- a/ForgeBlog/forgeblog/main.py
+++ b/ForgeBlog/forgeblog/main.py
@@ -21,7 +21,6 @@ from datetime import datetime
 import urllib2
 
 # Non-stdlib imports
-import pkg_resources
 import pymongo
 from tg import config, expose, validate, redirect, flash
 from tg.decorators import with_trailing_slash, without_trailing_slash
@@ -35,15 +34,16 @@ from webob import exc
 from ming.orm import session
 
 # Pyforge-specific imports
-from allura.app import Application, ConfigOption, SitemapEntry
+from allura.app import Application, SitemapEntry
 from allura.app import DefaultAdminController
 from allura.lib import helpers as h
-from allura.lib.search import search, SearchError
+from allura.lib.search import search_app
 from allura.lib.decorators import require_post, Property
 from allura.lib.security import has_access, require_access
 from allura.lib import widgets as w
 from allura.lib.widgets.subscriptions import SubscribeForm
 from allura.lib.widgets import form_fields as ffw
+from allura.lib.widgets.search import SearchResults
 from allura import model as M
 from allura.controllers import BaseController, AppDiscussionController
 
@@ -67,6 +67,7 @@ class W:
     attachment_list = ffw.AttachmentList()
     preview_post_form = widgets.PreviewPostForm()
     subscribe_form = SubscribeForm()
+    search_results = SearchResults()
 
 class ForgeBlogApp(Application):
     __version__ = version.__version__
@@ -203,31 +204,26 @@ class RootController(BaseController):
         c.pager = W.pager
         return dict(posts=posts, page=page, limit=limit, count=post_count)
 
+    @with_trailing_slash
     @expose('jinja:forgeblog:templates/blog/search.html')
     @validate(dict(q=validators.UnicodeString(if_empty=None),
-                   history=validators.StringBool(if_empty=False)))
-    def search(self, q=None, history=None, **kw):
-        'local tool search'
-        results = []
-        search_error = None
-        count=0
-        if not q:
-            q = ''
-        else:
-            try:
-                results = search(
-                    q,
-                    fq=[
-                        'state_s:published',
-                        'is_history_b:%s' % history,
-                        'project_id_s:%s' % c.project._id,
-                        'mount_point_s:%s'% c.app.config.options.mount_point ],
-                    short_timeout=True,
-                    ignore_errors=False)
-            except SearchError as e:
-                search_error = e
-            if results: count=results.hits
-        return dict(q=q, history=history, results=results or [], count=count, search_error=search_error)
+                   history=validators.StringBool(if_empty=False),
+                   search_comments=validators.StringBool(if_empty=False),
+                   project=validators.StringBool(if_empty=False)))
+    def search(self, q=None, history=None, search_comments=None, project=None, limit=None,
page=0, **kw):
+        c.search_results = W.search_results
+        search_params = kw
+        search_params.update({
+            'q': q or '',
+            'history': history,
+            'search_comments': search_comments,
+            'project': project,
+            'limit': limit,
+            'page': page,
+            'allowed_types': ['Blog Post', 'Blog Post Snapshot'],
+            'fq': ['state_s:published']
+        })
+        return search_app(**search_params)
 
     @expose('jinja:forgeblog:templates/blog/edit_post.html')
     @without_trailing_slash

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b636c9d2/ForgeBlog/forgeblog/model/blog.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/model/blog.py b/ForgeBlog/forgeblog/model/blog.py
index 1801c22..d5ec233 100644
--- a/ForgeBlog/forgeblog/model/blog.py
+++ b/ForgeBlog/forgeblog/model/blog.py
@@ -74,8 +74,7 @@ class BlogPostSnapshot(M.Snapshot):
             return None
         result = super(BlogPostSnapshot, self).index()
         result.update(
-            title='Version %d of %s' % (
-                self.version, orig.shorthand_id()),
+            title='%s (version %d)' % (orig.title, self.version),
             type_s=self.type_s,
             text=self.data.text)
         return result
@@ -201,7 +200,7 @@ class BlogPost(M.VersionedArtifact, ActivityObject):
     def index(self):
         result = super(BlogPost, self).index()
         result.update(
-            title=self.slug,
+            title=self.title,
             type_s=self.type_s,
             state_s=self.state,
             snippet_s='%s: %s' % (self.title, h.text.truncate(self.text, 200)),

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b636c9d2/ForgeBlog/forgeblog/templates/blog/search.html
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/templates/blog/search.html b/ForgeBlog/forgeblog/templates/blog/search.html
index b8574ca..76b4372 100644
--- a/ForgeBlog/forgeblog/templates/blog/search.html
+++ b/ForgeBlog/forgeblog/templates/blog/search.html
@@ -20,29 +20,10 @@
 
 {% block title %}{{c.project.name}} / {{c.app.config.options.mount_label}} / Search{% endblock
%}
 
-{% block header %}ForgeBlog Search{% endblock %}
+{% block header %}Search {{c.app.config.options.mount_point}}: {{q}}{% endblock %}
 
 {% block content %}
-  <form method="GET" action="search" class="grid-19">
-    <input type="text" name="q" value="{{q}}"/><br/>
-    Search history? <input type="checkbox" name="history" {% if history %}checked="checked"{%
endif %}/><br/>
-    <input type="submit" value="Search"/>
-  </form>
-  <div style="clear: both">&nbsp;</div>
-  {% if search_error %}
-  <p>{{ search_error }}</p>
-  {% elif count==0 and q %}
-  <p>No results.</p>
-  {% elif count==1 and q %}
-  <p>{{count}} result.</p>
-  {% elif count > 1 and q %}
-  <p>{{count}} results.</p>
-  {% endif %}
-  {% for doc in results %}
-  <div>
-    <div class="grid-19"><a href="{{doc['url_s']}}">{{ h.get_first(doc, 'title')
}}</a></div>
-    <p>{{doc.get('snippet_s', '...')}}</p>
-    <hr/>
-  </div>
-  {% endfor %}
+  {{c.search_results.display(results=results,q=q,history=history,
+     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 %}


Mime
View raw message