[Patches] [PATCH] Bug 3216 UNIMARC author facets
koha-patchbot at kohaaloha.com
koha-patchbot at kohaaloha.com
Sat Dec 3 14:15:25 NZDT 2011
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Demians?= <f.demians at tamil.fr>
Date: Fri, 2 Dec 2011 07:56:27 +0100
Subject: [PATCH] Bug 3216 UNIMARC author facets
Add 700$b to UNIMARC author facets.
Other facets subfields could be added now. For example, other subjects subfields.
---
C4/Koha.pm | 2 +-
C4/Search.pm | 30 +++++++++++++++---------------
2 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/C4/Koha.pm b/C4/Koha.pm
index 06b2ec5..a28044b 100644
--- a/C4/Koha.pm
+++ b/C4/Koha.pm
@@ -703,7 +703,7 @@ sub getFacets {
link_value => 'au',
label_value => 'Authors',
tags => [ '700', '701', '702', ],
- subfield => 'a',
+ subfield => 'ab',
},
{
link_value => 'se',
diff --git a/C4/Search.pm b/C4/Search.pm
index 98db887..13c10e4 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -473,7 +473,7 @@ sub getRecords {
($facets->[$k]) or next;
my @fcodes = @{$facets->[$k]->{'tags'}};
my $sfcode = $facets->[$k]->{'subfield'};
-
+ my @sfcodes = split('', $sfcode);
for ( my $j = 0 ; $j < $jmax ; $j++ ) {
my $render_record = $results[ $i - 1 ]->record($j)->render();
my @used_datas = ();
@@ -483,22 +483,22 @@ sub getRecords {
# avoid first line
my $field_pattern = '\n'.$fcode.' ([^\n]+)';
my @field_tokens = ( $render_record =~ /$field_pattern/g ) ;
-
foreach my $field_token (@field_tokens) {
- my $subfield_pattern = '\$'.$sfcode.' ([^\$]+)';
- my @subfield_values = ( $field_token =~ /$subfield_pattern/g );
-
- foreach my $subfield_value (@subfield_values) {
-
- my $data = $subfield_value;
- $data =~ s/^\s+//; # trim left
- $data =~ s/\s+$//; # trim right
-
- unless ( $data ~~ @used_datas ) {
- $facets_counter->{ $facets->[$k]->{'link_value'} }->{$data}++;
- push @used_datas, $data;
+ my @subf = ( $field_token =~ /\$([a-zA-Z0-9]) ([^\$]+)/g );
+ my @values;
+ for (my $i = 0; $i < @subf; $i += 2) {
+ if ( $sfcode =~ $subf[$i] ) {
+ my $value = $subf[$i+1];
+ $value =~ s/^ *//;
+ $value =~ s/ *$//;
+ push @values, $value;
}
- } # subfields
+ }
+ my $data = join(', ', @values);
+ unless ( $data ~~ @used_datas ) {
+ $facets_counter->{ $facets->[$k]->{'link_value'} }->{$data}++;
+ push @used_datas, $data;
+ }
} # fields
} # field codes
} # records
--
1.7.6.1
More information about the Patches
mailing list