[open-ils-commits] r17586 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Search (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Sep 10 16:11:20 EDT 2010
Author: miker
Date: 2010-09-10 16:11:15 -0400 (Fri, 10 Sep 2010)
New Revision: 17586
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
Log:
Allow the caller to specify a max number of facet values per facet
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm 2010-09-10 19:07:45 UTC (rev 17585)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm 2010-09-10 20:11:15 UTC (rev 17586)
@@ -1316,10 +1316,28 @@
my $self = shift;
my $client = shift;
my $key = shift;
+ my $limit = shift;
return undef unless ($key and $key =~ /_facets$/);
- return $cache->get_cache($key) || {};
+ my $blob = $cache->get_cache($key) || {};
+
+ my $facets = {};
+ if ($limit) {
+ for my $f ( keys %$blob ) {
+ my @sorted = map{ { $$_[1] => $$_[0] } } sort {$$b[0] <=> $$a[0]} map { [$_, $$blob{$f}{$_}] } keys %{ $$blob{$f} };
+ @sorted = @sorted[0 .. $limit - 1] if (scalar(@sorted) > $limit);
+ for my $s ( @sorted ) {
+ my ($k) = keys(%$s);
+ my ($v) = values(%$s);
+ $$facets{$f}{$k} = $v;
+ }
+ }
+ } else {
+ $facets = $blob;
+ }
+
+ return $facets;
}
__PACKAGE__->register_method(
More information about the open-ils-commits
mailing list