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/04/24 19:16:22 UTC

[13/28] git commit: [#2835] ticket:292 Better search for chat

[#2835] ticket:292 Better search for chat


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

Branch: refs/heads/db/2835
Commit: 7b42446932fd105962df49d38b665514f5fe1429
Parents: 91e308c
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Mar 25 14:32:56 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Apr 24 16:34:41 2013 +0000

----------------------------------------------------------------------
 .../allura/templates/widgets/search_results.html   |    6 ++-
 ForgeChat/forgechat/main.py                        |   43 ++++++---------
 ForgeChat/forgechat/templates/chat/search.html     |   29 ++--------
 3 files changed, 28 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7b424469/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 500f639..debb450 100644
--- a/Allura/allura/templates/widgets/search_results.html
+++ b/Allura/allura/templates/widgets/search_results.html
@@ -44,8 +44,10 @@
       <label for="search-comments">Search comments?</label>
       <input id="search-comments" type="checkbox" name="search_comments"{% if comments %} checked{% endif %}>
     {% endif %}
-    <label for="search-history">Search history?</label>
-    <input id="search-history" type="checkbox" name="history"{% if history %} checked{% endif %}>
+    {% if not search_history_disable %}
+      <label for="search-history">Search history?</label>
+      <input id="search-history" type="checkbox" name="history"{% if history %} checked{% endif %}>
+    {% endif %}
   </div>
 </form>
 <div style="clear:both">&nbsp;</div>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7b424469/ForgeChat/forgechat/main.py
----------------------------------------------------------------------
diff --git a/ForgeChat/forgechat/main.py b/ForgeChat/forgechat/main.py
index 5150d61..05eaf94 100644
--- a/ForgeChat/forgechat/main.py
+++ b/ForgeChat/forgechat/main.py
@@ -22,19 +22,18 @@ import logging
 from datetime import date, time, datetime, timedelta
 
 # Non-stdlib imports
-import pkg_resources
 from tg import expose, validate, redirect, flash
 from tg.decorators import with_trailing_slash
 from pylons import tmpl_context as c, app_globals as g
-from pylons import request
 from formencode import validators
 
 # Pyforge-specific imports
 from allura.app import Application, ConfigOption, SitemapEntry, 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
 from allura.lib.security import require_access
+from allura.lib.widgets.search import SearchResults
 from allura import model as M
 from allura.controllers import BaseController
 
@@ -135,30 +134,24 @@ class RootController(BaseController):
         now = datetime.utcnow()
         redirect(c.app.url + now.strftime('%Y/%m/%d/'))
 
+    @with_trailing_slash
     @expose('jinja:forgechat:templates/chat/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=[
-                        '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)
+                   project=validators.StringBool(if_empty=False)))
+    def search(self, q=None, project=None, limit=None, page=0, **kw):
+        c.search_results = SearchResults()
+        search_params = kw
+        search_params.update({
+            'q': q or '',
+            'project': project,
+            'limit': limit,
+            'page': page,
+            'allowed_types': ['Chat Message'],
+        })
+        d = search_app(**search_params)
+        d['search_comments_disable'] = True
+        d['search_history_disable'] = True
+        return d
 
     @expose()
     def _lookup(self, y, m, d, *rest):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7b424469/ForgeChat/forgechat/templates/chat/search.html
----------------------------------------------------------------------
diff --git a/ForgeChat/forgechat/templates/chat/search.html b/ForgeChat/forgechat/templates/chat/search.html
index 59566c6..0447586 100644
--- a/ForgeChat/forgechat/templates/chat/search.html
+++ b/ForgeChat/forgechat/templates/chat/search.html
@@ -21,30 +21,13 @@
 
 {% block title %}{{c.project.name}} / {{c.app.config.options.mount_label}} / Search{% endblock %}
 
-{% block header %}ForgeChat Search{% endblock %}
+{% block header %}Search {{c.app.config.options.mount_point}}: {{q}}{% endblock %}
 
 {% block content %}
   {{ clib.checkout_info(c.app) }}
-  <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>
-  {% 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 class="grid-19">
-    <a href="{{doc['url_s']}}">{{ h.get_first(doc, 'title') }}</a><br/>
-    <pre>{{doc|pprint}}</pre>
-    <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,
+     search_comments_disable=search_comments_disable,
+     search_history_disable=search_history_disable)}}
 {% endblock %}