Port facet count limiting from 2.5 stock
authorJeff Godin <jgodin@tadl.org>
Mon, 23 Dec 2013 17:06:02 +0000 (12:06 -0500)
committerJeff Godin <jgodin@tadl.org>
Mon, 23 Dec 2013 17:06:02 +0000 (12:06 -0500)
Port changes to facet count limiting (and remove the in-TT sort).

Signed-off-by: Jeff Godin <jgodin@tadl.org>
templates_tadlskin/opac/parts/config.tt2
templates_tadlskin/opac/parts/result/facets.tt2

index 2e34345..9f68d34 100644 (file)
@@ -74,7 +74,7 @@ facet.display = [
     {facet_class => 'author',  facet_order => ['personal', 'corporate']},
     {facet_class => 'series',  facet_order => ['seriestitle']},
 ];
-
+facet.default_display_count = 10;
 
 ##############################################################################
 # TADL overrides for display
index 009f448..bbb1844 100644 (file)
@@ -8,6 +8,10 @@ selected_facets = CGI.param('facet') || [];
 # sorted list of search facets
 sorted_facets = [];
 
+# we'll clobber the facet. "namespace" later
+# Provide a default value if unset in config.tt2
+DEFAULT_DISPLAY_COUNT = facet.default_display_count || 5;
+
 IF facet.display;
 
     # facet display configuration present.  Traverse the 
@@ -37,19 +41,17 @@ ELSE;
     FOR facet IN ctx.search_facets.values;
         labels.push(facet.cmf.label);
     END;
-    
-    FOR facet_label IN labels.sort;
-        FOR facet IN ctx.search_facets.values;
-            IF facet.cmf.label == facet_label;
-                sorted_facets.push(facet);
-            END;
-        END;
-    END;
+
+    # We used to do a sort here, but now that's handled in EGCatLoader.
+    sorted_facets = ctx.search_facets.values;
 END;
 
+display_count_by_cmf = {};
+
 FOR facet IN sorted_facets;
     fclass = facet.cmf.field_class;
     fname = facet.cmf.name;
+    fid = facet.cmf.id;
     close_key = fclass _ fname %]
 
     <div class="facet_box_temp">
@@ -93,6 +95,14 @@ FOR facet IN sorted_facets;
                         new_facets.push(selected);
                     END;
                 END;
+
+                display_count_by_cmf.$fid = display_count_by_cmf.$fid || 0;
+
+                NEXT UNLESS long_facets.grep(long_key).0 OR
+                    display_count_by_cmf.$fid < DEFAULT_DISPLAY_COUNT;
+
+                display_count_by_cmf.$fid = display_count_by_cmf.$fid + 1;
+
                 IF this_selected;
                     # This facet is already selected by the user. 
                     # Link removes the facet from the set of selected facets.