allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [37/38] git commit: [#4019] ticket:560 Added docstrings & fixed tests for facets functions
Date Wed, 30 Apr 2014 18:16:09 GMT
[#4019] ticket:560 Added docstrings & fixed tests for facets functions


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

Branch: refs/heads/master
Commit: c4e761944cc0aaaac2f3526a6296823ad931419e
Parents: ed3bb2a
Author: Ferens Dmitriy <ferensdima@gmail.com>
Authored: Fri Mar 28 13:46:01 2014 +0200
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Apr 30 15:55:15 2014 +0000

----------------------------------------------------------------------
 ForgeTracker/forgetracker/search.py             | 26 +++++++++++++++-----
 .../forgetracker/tests/unit/test_search.py      |  3 ++-
 2 files changed, 22 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/c4e76194/ForgeTracker/forgetracker/search.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/search.py b/ForgeTracker/forgetracker/search.py
index 7d0bcc9..8dfa3a8 100644
--- a/ForgeTracker/forgetracker/search.py
+++ b/ForgeTracker/forgetracker/search.py
@@ -28,7 +28,13 @@ FACET_PARAMS = {
 }
 
 
-def query_filter_choices(arg=None, final_result=None):
+def query_filter_choices(arg=None, final_obj_list=None):
+    """
+    Makes solr query and returns facets for tickets.
+
+    :param arg: solr query, string
+    :param final_obj_list: final list of tickets
+    """
     params = {
         'short_timeout': True,
         'fq': [
@@ -40,19 +46,27 @@ def query_filter_choices(arg=None, final_result=None):
     }
     params.update(FACET_PARAMS)
     result = search(arg, **params)
-    return get_facets(result, final_result)
+    return get_facets(result, final_obj_list)
+
 
+def get_facets(solr_hit, final_obj_list=None):
+    """
+    Returns solr facets by passed solr result.
+    If you want to retrieve facets for only a subset of solr results, you
+    can pass this subset as ``final_obj_lis`` arg.
 
-def get_facets(solr_hit, final_result=None):
+    :param solr_hit: solr result instance.
+    :param final_obj_list: final list of objects facets should be filtered on.
+    """
     result = {}
     if solr_hit is not None:
         for facet_name, values in solr_hit.facets['facet_fields'].iteritems():
             field_name = facet_name.rsplit('_s', 1)[0]
             values = [(values[i], values[i+1]) for i in xrange(0, len(values), 2)]
-            if final_result:
+            if final_obj_list:
                 available_values = []
-                for ticket in final_result:
-                    solr_data = ticket.index()
+                for obj in final_obj_list:
+                    solr_data = obj.index()
                     if facet_name in solr_data:
                         available_values.append(solr_data[facet_name])
 

http://git-wip-us.apache.org/repos/asf/allura/blob/c4e76194/ForgeTracker/forgetracker/tests/unit/test_search.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/unit/test_search.py b/ForgeTracker/forgetracker/tests/unit/test_search.py
index 9a2fafa..e991c28 100644
--- a/ForgeTracker/forgetracker/tests/unit/test_search.py
+++ b/ForgeTracker/forgetracker/tests/unit/test_search.py
@@ -46,7 +46,8 @@ def test_query_filter_choices(c, search):
     result = query_filter_choices()
     params = {'short_timeout': True,
               'fq': ['project_id_s:%s' % c.project._id,
-                     'mount_point_s:%s' % c.app.config.options.mount_point],
+                     'mount_point_s:%s' % c.app.config.options.mount_point,
+                     'type_s:Ticket'],
               'rows': 0,
               'facet': 'true',
               'facet.field': ['_milestone_s', 'status_s',


Mime
View raw message