You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2014/09/18 09:30:05 UTC

[30/43] git commit: [#7656] ticket:648 Refactor projects search fn to generic one and add fn for users

[#7656] ticket:648 Refactor projects search fn to generic one and add fn for users


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

Branch: refs/heads/je/42cc_7656
Commit: c3bfa048732c9cfe6b860d36b1ba793f8f2e02fb
Parents: 5b6f3d1
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Sep 9 13:08:44 2014 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Sep 18 09:33:57 2014 +0300

----------------------------------------------------------------------
 Allura/allura/lib/search.py | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/c3bfa048/Allura/allura/lib/search.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/search.py b/Allura/allura/lib/search.py
index c0f45cc..49a3ad5 100644
--- a/Allura/allura/lib/search.py
+++ b/Allura/allura/lib/search.py
@@ -159,26 +159,35 @@ 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, **kw):
-    """Performs SOLR search for a project.
+def site_admin_search(model, q, field, **kw):
+    """Performs SOLR search for a given model.
+
+    Probably you should not use it directly. Use one of the specific functions below.
 
     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()
+    # first, grab a object and get the fields that it indexes
+    obj = model.query.find().first()
+    if obj is None:
+        return  # if there are no objects, we won't find anything
+    fields = obj.index()
     if field == '__custom__':
         # custom query -> query as is
-        q = p.translate_query(q, fields)
+        q = obj.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']
+        q = obj.translate_query(u'%s:"%s"' % (field, q), fields)
+    fq = [u'type_s:%s' % model.type_s]
     return search(q, fq=fq, ignore_errors=False, **kw)
 
+def search_projects(q, field, **kw):
+    from allura.model import Project
+    return site_admin_search(Project, q, field, **kw)
+
+def search_users(q, field, **kw):
+    from allura.model import User
+    return site_admin_search(User, q, field, **kw)
+
 
 def search_app(q='', fq=None, app=True, **kw):
     """Helper for app/project search.