allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [31/38] git commit: [#4019] ticket:560 Fixed filter choices for milestone view
Date Wed, 30 Apr 2014 18:16:03 GMT
[#4019] ticket:560 Fixed filter choices for milestone view


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

Branch: refs/heads/master
Commit: 4ab00ffa75d7a663ad28452a2c6736936ec75774
Parents: 32ec63a
Author: Ferens Dmitriy <ferensdima@gmail.com>
Authored: Fri Mar 21 11:42:54 2014 +0200
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Apr 30 15:55:14 2014 +0000

----------------------------------------------------------------------
 ForgeTracker/forgetracker/model/ticket.py |  5 ++--
 ForgeTracker/forgetracker/search.py       | 38 ++++++++++++++------------
 2 files changed, 23 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/4ab00ffa/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 439691c..bdf4e2e 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -1193,7 +1193,7 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
         return dict(tickets=tickets,
                     count=count, q=q, limit=limit, page=page, sort=sort,
                     filter=filter,
-                    filter_choices=tsearch.get_facets(matches),
+                    filter_choices=tsearch.get_facets(matches, tickets),
                     solr_error=solr_error, **kw)
 
     @classmethod
@@ -1212,11 +1212,10 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
             solr_sort = '%s %s' % (solr_col, sort_split[1])
         if not filter:
             result = cls.paged_query(app_config, user, query, sort=sort, limit=limit, page=page,
**kw)
-
             t = cls.query.find().first()
             if t:
                 search_query = cls.translate_query(search_query, t.index())
-            result['filter_choices'] = tsearch.query_filter_choices(search_query)
+            result['filter_choices'] = tsearch.query_filter_choices(search_query, result['tickets'])
         else:
             result = cls.paged_search(app_config, user, search_query, filter=filter,
                                       sort=solr_sort, limit=limit, page=page, **kw)

http://git-wip-us.apache.org/repos/asf/allura/blob/4ab00ffa/ForgeTracker/forgetracker/search.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/search.py b/ForgeTracker/forgetracker/search.py
index 6d8c4d8..07d04cf 100644
--- a/ForgeTracker/forgetracker/search.py
+++ b/ForgeTracker/forgetracker/search.py
@@ -14,7 +14,6 @@
 #       KIND, either express or implied.  See the License for the
 #       specific language governing permissions and limitations
 #       under the License.
-
 from pylons import tmpl_context as c
 
 from allura.lib.search import search
@@ -29,7 +28,7 @@ FACET_PARAMS = {
 }
 
 
-def query_filter_choices(arg=None):
+def query_filter_choices(arg=None, final_result=None):
     params = {
         'short_timeout': True,
         'fq': [
@@ -40,18 +39,23 @@ def query_filter_choices(arg=None):
     }
     params.update(FACET_PARAMS)
     result = search(arg, **params)
-    return get_facets(result)
-
-
-def get_facets(solr_hit):
-    if solr_hit is None:
-        return {}
-    def reformat(field):
-        name, val = field
-        # drop "_s"
-        name = name[:-2]
-        new_val = []
-        for i in range(0, len(val), 2):
-            new_val.append((val[i], val[i+1]))
-        return name, new_val
-    return dict(map(reformat, solr_hit.facets['facet_fields'].iteritems()))
+    return get_facets(result, final_result)
+
+
+def get_facets(solr_hit, final_result=None):
+    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:
+                available_values = []
+                for ticket in final_result:
+                    solr_data = ticket.index()
+                    if facet_name in solr_data:
+                        available_values.append(solr_data[facet_name])
+
+                values = filter(lambda v: v[0] in available_values, values)
+
+            result[field_name] = values
+    return result


Mime
View raw message