From acec3d1e2b85f75889427e074514a5b43e7e4f50 Mon Sep 17 00:00:00 2001 From: miker Date: Fri, 10 Sep 2010 20:11:15 +0000 Subject: [PATCH] Allow the caller to specify a max number of facet values per facet git-svn-id: svn://svn.open-ils.org/ILS/trunk@17586 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Search/Biblio.pm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm index 3d33837e3..bfe63e241 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm @@ -1316,10 +1316,28 @@ sub retrieve_cached_facets { 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( -- 2.11.0