incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [07/28] git commit: [#2835] ticket:292 Use new search on 'entire project search' page
Date Wed, 24 Apr 2013 18:13:41 GMT
[#2835] ticket:292 Use new search on 'entire project search' page


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

Branch: refs/heads/master
Commit: bfee10f6e49890a7583c47a2d9d6991b5b7a8e21
Parents: 1fc20bd
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Mar 25 15:51:38 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Apr 24 16:34:41 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/search.py                |   27 +++++-----
 Allura/allura/ext/search/search_main.py            |   39 ++++++++------
 Allura/allura/lib/search.py                        |   12 +++--
 Allura/allura/templates/search_index.html          |   37 ++------------
 .../allura/templates/widgets/search_results.html   |    3 +
 5 files changed, 53 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bfee10f6/Allura/allura/controllers/search.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/search.py b/Allura/allura/controllers/search.py
index 0a7e699..a58ee9f 100644
--- a/Allura/allura/controllers/search.py
+++ b/Allura/allura/controllers/search.py
@@ -22,7 +22,8 @@ from pylons import tmpl_context as c
 from webob import exc
 import pymongo
 
-from allura.lib import search
+from allura.lib.search import search_app
+from allura.lib.widgets.search import SearchResults
 from allura.app import SitemapEntry
 from allura import model as M
 from allura.lib.widgets import project_list as plw
@@ -30,6 +31,7 @@ from allura.controllers import BaseController
 
 class W:
     project_summary = plw.ProjectSummary()
+    search_results = SearchResults()
 
 class SearchController(BaseController):
 
@@ -38,18 +40,17 @@ class SearchController(BaseController):
                    history=V.StringBool(if_empty=False)))
     @with_trailing_slash
     def index(self, q=None, history=False, **kw):
-        results = []
-        count=0
-        if not q:
-            q = ''
-        else:
-            results = search.search(
-                q,
-                fq='is_history_b:%s' % history,
-                short_timeout=True)
-            if results: count=results.hits
-        return dict(q=q, history=history, results=results or [], count=count)
-
+        c.search_results = W.search_results
+        search_params = kw
+        search_params.update({
+            'q': q,
+            'history': history,
+            'app': False,
+        })
+        d = search_app(**search_params)
+        d['search_comments_disable'] = True
+        d['hide_app_project_switcher'] = True
+        return d
 
 class ProjectBrowseController(BaseController):
     def __init__(self, category_name=None, parent_category=None):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bfee10f6/Allura/allura/ext/search/search_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/search/search_main.py b/Allura/allura/ext/search/search_main.py
index bcb1ee9..9b709f4 100644
--- a/Allura/allura/ext/search/search_main.py
+++ b/Allura/allura/ext/search/search_main.py
@@ -25,7 +25,8 @@ from formencode import validators as V
 
 from allura.app import Application
 from allura import version
-from allura.lib import search
+from allura.lib.search import search_app
+from allura.lib.widgets.search import SearchResults
 from allura.controllers import BaseController
 
 log = logging.getLogger(__name__)
@@ -66,19 +67,23 @@ class SearchController(BaseController):
                    history=V.StringBool(if_empty=False)))
     @with_trailing_slash
     def index(self, q=None, history=None, **kw):
-        results = []
-        count=0
-        if not q:
-            q = ''
-        else:
-            pids = [c.project._id] + [
-                p._id for p in c.project.subprojects ]
-            project_match = ' OR '.join(
-                'project_id_s:%s' % pid
-                for pid in pids )
-            search_query = '%s AND is_history_b:%s AND (%s) AND -deleted_b:true' % (
-                q, history, project_match)
-            results = search.search(search_query, is_history_b=history, short_timeout=True)
-            if results: count=results.hits
-        return dict(q=q, history=history, results=results or [], count=count)
-
+        c.search_results = SearchResults()
+        pids = [c.project._id] + [
+            p._id for p in c.project.subprojects ]
+        project_match = ' OR '.join(
+            'project_id_s:%s' % pid
+            for pid in pids )
+        search_params = kw
+        search_params.update({
+            'q': q,
+            'history': history,
+            'app': False,
+            'fq': [
+                'project_id_s:(%s)' % project_match,
+                '-deleted_b:true',
+            ],
+        })
+        d = search_app(**search_params)
+        d['search_comments_disable'] = True
+        d['hide_app_project_switcher'] = True
+        return d

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bfee10f6/Allura/allura/lib/search.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/search.py b/Allura/allura/lib/search.py
index c541225..cf92af8 100644
--- a/Allura/allura/lib/search.py
+++ b/Allura/allura/lib/search.py
@@ -89,14 +89,15 @@ def search_artifact(atype, q, history=False, rows=10, short_timeout=False,
**kw)
     return search(q, fq=fq, rows=rows, short_timeout=short_timeout, ignore_errors=False,
**kw)
 
 
-def search_app(q='', fq=None, **kw):
-    """Helper for app search.
+def search_app(q='', fq=None, app=True, **kw):
+    """Helper for app/project search.
 
     Uses dismax query parser. Matches on `title` and `text`. Handles paging, sorting, etc
     """
     history = kw.pop('history', None)
-    if kw.pop('project', False):
-        redirect(c.project.url() + 'search?' + urlencode(dict(q=q, history=history)))
+    if app and kw.pop('project', False):
+        # Used from app's search controller. If `project` is True, redirect to 'entire project
search' page
+        redirect(c.project.url() + 'search/?' + urlencode(dict(q=q, history=history)))
     search_comments = kw.pop('search_comments', None)
     limit = kw.pop('limit', None)
     page = kw.pop('page', 0)
@@ -133,6 +134,9 @@ def search_app(q='', fq=None, **kw):
             'hl.simple.post': '</strong>',
             'sort': sort,
         }
+        if not app:
+            # Not app-restricted search. Use only provided filter query (fq)
+            search_params['fq'] = fq
         if not history:
            search_params['fq'].append('is_history_b:False')
         if parser == 'standard':

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bfee10f6/Allura/allura/templates/search_index.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/search_index.html b/Allura/allura/templates/search_index.html
index ea2b566..13fa9d1 100644
--- a/Allura/allura/templates/search_index.html
+++ b/Allura/allura/templates/search_index.html
@@ -24,35 +24,10 @@
 {% block header %}Search Project: {{q}}{% endblock %}
 
 {% block content %}
-  <div class="grid-24">
-  <form method="GET" action="search">
-    <input type="text" name="q" value="{{q}}" class="title"/><br/>
-    Search history? <input type="checkbox" name="history" {% if history %}checked{% endif
%}/><br/>
-    &nbsp;<br/>
-    <input type="submit" value="Search"/>
-  </form>
-  {% if 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 %}
-  <hr/>
-  </div>
-
-  <div class="grid-24">
-  <ol>
-  {% for doc in results %}
-  <li>
-    <a href="{{doc['url_s']}}">
-       {{- h.get_first(doc, 'title') or h.get_first(doc, 'title_s') -}}  {#-  title_s is
legacy -#}
-    </a>
-    {% if doc.get('snippet') %}
-      <p>{{doc['snippet']|safe}}</p>
-    {% endif %}
-  </li>
-  {% endfor %}
-  </ol>
-  </div>
+  {{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,
+     hide_app_project_switcher=hide_app_project_switcher)}}
 {% endblock %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bfee10f6/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 debb450..2eaaf61 100644
--- a/Allura/allura/templates/widgets/search_results.html
+++ b/Allura/allura/templates/widgets/search_results.html
@@ -31,6 +31,8 @@
     </a>
   </div>
   {% endif %}
+  <div style="clear:both"></div>
+  {% if not hide_app_project_switcher %}
   <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 %}>
@@ -38,6 +40,7 @@
     <input type="radio" name="project" value="1" id="search-project" {% if search_project
%}checked{% endif %}>
     <label for="search-project">Search entire project</label>
   </div>
+  {% endif %}
   <div class="grid-9">
     {% if not search_comments_disable %}
       {% set comments = request.GET['search_comments'] %}


Mime
View raw message