allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [14/23] git commit: [#7278] ticket:612 Basic search capabilities
Date Wed, 20 Aug 2014 07:10:53 GMT
[#7278] ticket:612 Basic search capabilities


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

Branch: refs/heads/je/42cc_7278
Commit: 6672fdaeec35ba5b9d0b8e68affb29b2c7a1f918
Parents: 1efdf48
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Aug 1 13:09:28 2014 +0300
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Tue Aug 19 12:31:50 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/site_admin.py         | 16 +++++++++++++--
 Allura/allura/lib/search.py                     | 21 ++++++++++++++++++++
 Allura/allura/lib/widgets/forms.py              |  6 +++++-
 Allura/allura/model/project.py                  |  5 +++++
 .../templates/site_admin_search_projects.html   | 19 ++++++++++++++++++
 5 files changed, 64 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/6672fdae/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index 2267999..4e03453 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -34,6 +34,7 @@ from allura.lib import helpers as h
 from allura.lib import validators as v
 from allura.lib.decorators import require_post
 from allura.lib.plugin import SiteAdminExtension
+from allura.lib import search
 from allura.lib.security import require_access
 from allura.lib.widgets import form_fields as ffw
 from allura.ext.admin.widgets import AuditLog
@@ -278,12 +279,23 @@ class SiteAdminController(object):
     @validate(validators=dict(q=validators.UnicodeString(if_empty=None),
                               limit=validators.Int(if_invalid=None),
                               page=validators.Int(if_empty=0, if_invalid=0)))
-    def search_projects(self, q=None, page=0, limit=None, **kw):
+    def search_projects(self, q=None, f=None, page=0, limit=None, **kw):
         c.search_projects_form = W.search_projects_form
         c.page_list = W.page_list
         c.page_size = W.page_size
+        count = 0
+        projects = []
+        limit, page, start = g.handle_paging(limit, page, default=25)
+        if q:
+            match = search.search_projects(q, f, rows=limit, start=start)
+            if match:
+                count = match.hits
+                projects = match.docs
         return {
-            'count': 2,
+            'q': q,
+            'f': f,
+            'projects': projects,
+            'count': count,
             'page': page,
             'limit': limit,
         }

http://git-wip-us.apache.org/repos/asf/allura/blob/6672fdae/Allura/allura/lib/search.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/search.py b/Allura/allura/lib/search.py
index b0d7e4b..d699d28 100644
--- a/Allura/allura/lib/search.py
+++ b/Allura/allura/lib/search.py
@@ -159,6 +159,27 @@ def search_artifact(atype, q, history=False, rows=10, short_timeout=False,
filte
     return search(q, fq=fq, rows=rows, short_timeout=short_timeout, ignore_errors=False,
**kw)
 
 
+def search_projects(q, field, rows=10, short_timeout=False, **kw):
+    """Performs SOLR search for a project.
+
+    Raises SearchError if SOLR returns an error.
+    """
+    # first, grab a project and get the fields that it indexes
+    from allura.model import Project
+    p = Project.query.find().first()
+    if p is None:
+        return  # if there are no projects, we won't find anything
+    fields = p.index()
+    if field == '__custom__':
+        # custom query -> query as is
+        q = p.translate_query(q, fields)
+    else:
+        # construct query for a specific selected field
+        q = p.translate_query(u'%s:%s' % (field, q), fields)
+    fq = [u'type_s:Project']
+    return search(q, fq=fq, rows=rows, short_timeout=short_timeout, ignore_errors=False,
**kw)
+
+
 def search_app(q='', fq=None, app=True, **kw):
     """Helper for app/project search.
 

http://git-wip-us.apache.org/repos/asf/allura/blob/6672fdae/Allura/allura/lib/widgets/forms.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py
index a8f2dda..75194ab 100644
--- a/Allura/allura/lib/widgets/forms.py
+++ b/Allura/allura/lib/widgets/forms.py
@@ -1095,7 +1095,11 @@ class SearchProjectsForm(ForgeForm):
                 ew.SingleSelectField(
                     name='f',
                     show_label=False,
-                    options=['shortname']),
+                    options=[
+                        ew.Option(py_value='shortname', label='shortname'),
+                        ew.Option(py_value='name', label='full name'),
+                        ew.Option(py_value='__custom__', label='custom query'),
+                    ]),
                 ew.InputField(name='q', show_label=False),
                 ew.SubmitButton(
                     show_label=False,

http://git-wip-us.apache.org/repos/asf/allura/blob/6672fdae/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 9db3bcd..e214df4 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -252,6 +252,11 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
     # transient properties
     notifications_disabled = False
 
+    @classmethod
+    def translate_query(cls, q, fields):
+        from .artifact import Artifact
+        return Artifact.translate_query(q, fields)
+
     @property
     def activity_name(self):
         return self.name

http://git-wip-us.apache.org/repos/asf/allura/blob/6672fdae/Allura/allura/templates/site_admin_search_projects.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin_search_projects.html b/Allura/allura/templates/site_admin_search_projects.html
index 51d6969..260576a 100644
--- a/Allura/allura/templates/site_admin_search_projects.html
+++ b/Allura/allura/templates/site_admin_search_projects.html
@@ -26,6 +26,25 @@
     {{ c.search_projects_form.display() }}
   </div>
 
+  {% if projects %}
+    <table>
+      <tr>
+        <th>Short name</th>
+        <th>Full name</th>
+        <th>Registered</th>
+        <th>Deleted?</th>
+      </tr>
+    {% for p in projects %}
+      <tr>
+        <td><a href="{{ p['url_s'] }}">{{ p['shortname_s'] }}</a></td>
+        <td>{{ p['name_s'] }}</td>
+        <td>{{ p['registration_dt'] }}</td>
+        <td>{{ 'Yes' if p['deleted_b'] else 'No' }}</td>
+      </tr>
+    {% endfor %}
+    </table>
+  {% endif %}
+
   <div class="grid-19">
     {{c.page_list.display(limit=limit, page=page, count=count)}}
     {{c.page_size.display(limit=limit, page=page, count=count)}}


Mime
View raw message