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 2014/09/19 22:04:25 UTC

[11/26] 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/6c7ca9a5
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/6c7ca9a5
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/6c7ca9a5

Branch: refs/heads/master
Commit: 6c7ca9a5a10e9210d855d3eefe2413afc305edc0
Parents: 1371cc3
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Sep 9 13:08:44 2014 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Fri Sep 19 19:35:39 2014 +0000

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


http://git-wip-us.apache.org/repos/asf/allura/blob/6c7ca9a5/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.