[Patches] [PATCH] Bug 3216 UNIMARC author facets
koha-patchbot at kohaaloha.com
koha-patchbot at kohaaloha.com
Sat Dec 3 14:16:18 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.
Following patches are required to handle better MARC21 subfields and choose other
subfields to deal with UNIMARC format.
---
C4/Koha.pm | 118 +++++++++++++++++++++++++++------------------------------
C4/Search.pm | 49 ++++++++++--------------
2 files changed, 77 insertions(+), 90 deletions(-)
diff --git a/C4/Koha.pm b/C4/Koha.pm
index 06b2ec5..4d447ef 100644
--- a/C4/Koha.pm
+++ b/C4/Koha.pm
@@ -681,95 +681,89 @@ sub getFacets {
if ( C4::Context->preference("marcflavour") eq "UNIMARC" ) {
$facets = [
{
- link_value => 'su-to',
- label_value => 'Topics',
- tags =>
- [ '600', '601', '602', '603', '604', '605', '606', '610' ],
- subfield => 'a',
+ idx => 'su-to',
+ label => 'Topics',
+ tags => [ qw/ 600a 601a 602a 603a 604a 605a 606ax 610a/ ],
+ sep => ' - ',
},
{
- link_value => 'su-geo',
- label_value => 'Places',
- tags => ['651'],
- subfield => 'a',
+ idx => 'su-geo',
+ label => 'Places',
+ tags => [ qw/ 651a / ],
+ sep => ' - ',
},
{
- link_value => 'su-ut',
- label_value => 'Titles',
- tags => [ '500', '501', '502', '503', '504', ],
- subfield => 'a',
+ idx => 'su-ut',
+ label => 'Titles',
+ tags => [ qw/ 500a 501a 502a 503a 504a / ],
+ sep => ', ',
},
{
- link_value => 'au',
- label_value => 'Authors',
- tags => [ '700', '701', '702', ],
- subfield => 'a',
+ idx => 'au',
+ label => 'Authors',
+ tags => [ qw/ 700ab 701ab 702ab / ],
+ sep => ', ',
},
{
- link_value => 'se',
- label_value => 'Series',
- tags => ['225'],
- subfield => 'a',
+ idx => 'se',
+ label => 'Series',
+ tags => [ qw/ 225a / ],
+ sep => ', ',
},
- ];
-
- my $library_facet;
-
- $library_facet = {
- link_value => 'branch',
- label_value => 'Libraries',
- tags => [ '995', ],
- subfield => 'b',
- expanded => '1',
- };
- push @$facets, $library_facet unless C4::Context->preference("singleBranchMode");
+ ];
+ my $library_facet = {
+ idx => 'branch',
+ label => 'Libraries',
+ tags => [ qw/ 995b / ],
+ expanded => '1',
+ };
+ push @$facets, $library_facet unless C4::Context->preference("singleBranchMode");
}
else {
$facets = [
{
- link_value => 'su-to',
- label_value => 'Topics',
- tags => ['650'],
- subfield => 'a',
+ idx => 'su-to',
+ label => 'Topics',
+ tags => [ qw/ 650a / ],
+ sep => '--',
},
-
# {
- # link_value => 'su-na',
- # label_value => 'People and Organizations',
- # tags => ['600', '610', '611'],
- # subfield => 'a',
+ # idx => 'su-na',
+ # label => 'People and Organizations',
+ # tags => [ qw/ 600a 610a 611a / ],
+ # sep => 'a',
# },
{
- link_value => 'su-geo',
- label_value => 'Places',
- tags => ['651'],
- subfield => 'a',
+ idx => 'su-geo',
+ label => 'Places',
+ tags => [ qw/ 651a / ],
+ sep => '--',
},
{
- link_value => 'su-ut',
- label_value => 'Titles',
- tags => ['630'],
- subfield => 'a',
+ idx => 'su-ut',
+ label => 'Titles',
+ tags => [ qw/ 630a / ],
+ sep => '--',
},
{
- link_value => 'au',
- label_value => 'Authors',
- tags => [ '100', '110', '700', ],
- subfield => 'a',
+ idx => 'au',
+ label => 'Authors',
+ tags => [ qw/ 100a 110a 700a / ],
+ sep => ', ',
},
{
- link_value => 'se',
- label_value => 'Series',
- tags => [ '440', '490', ],
- subfield => 'a',
+ idx => 'se',
+ label => 'Series',
+ tags => [ qw/ 440a 490a / ],
+ sep => ', ',
},
];
my $library_facet;
$library_facet = {
- link_value => 'branch',
- label_value => 'Libraries',
- tags => [ '952', ],
- subfield => 'b',
+ idx => 'branch',
+ label => 'Libraries',
+ tags => [ qw/ 952b / ],
+ sep => ', ',
expanded => '1',
};
push @$facets, $library_facet unless C4::Context->preference("singleBranchMode");
diff --git a/C4/Search.pm b/C4/Search.pm
index 98db887..a48db28 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -468,46 +468,39 @@ sub getRecords {
if ( !$scan && $servers[ $i - 1 ] =~ /biblioserver/ ) {
my $jmax = $size>$facets_maxrecs? $facets_maxrecs: $size;
-
- for ( my $k = 0 ; $k <= @$facets ; $k++ ) {
- ($facets->[$k]) or next;
- my @fcodes = @{$facets->[$k]->{'tags'}};
- my $sfcode = $facets->[$k]->{'subfield'};
-
+ for my $facet ( @$facets ) {
for ( my $j = 0 ; $j < $jmax ; $j++ ) {
my $render_record = $results[ $i - 1 ]->record($j)->render();
my @used_datas = ();
-
- foreach my $fcode (@fcodes) {
-
+ foreach my $tag ( @{$facet->{tags}} ) {
# avoid first line
- my $field_pattern = '\n'.$fcode.' ([^\n]+)';
+ my $tag_num = substr($tag, 0, 3);
+ my $letters = substr($tag, 3);
+ my $field_pattern = '\n' . $tag_num . ' ([^\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 ( $letters =~ $subf[$i] ) {
+ my $value = $subf[$i+1];
+ $value =~ s/^ *//;
+ $value =~ s/ *$//;
+ push @values, $value;
}
- } # subfields
+ }
+ my $data = join($facet->{sep}, @values);
+ unless ( $data ~~ @used_datas ) {
+ $facets_counter->{ $facet->{idx} }->{$data}++;
+ push @used_datas, $data;
+ }
} # fields
} # field codes
} # records
-
- $facets_info->{ $facets->[$k]->{'link_value'} }->{'label_value'} = $facets->[$k]->{'label_value'};
- $facets_info->{ $facets->[$k]->{'link_value'} }->{'expanded'} = $facets->[$k]->{'expanded'};
+ $facets_info->{ $facet->{idx} }->{label_value} = $facet->{label};
+ $facets_info->{ $facet->{idx} }->{expanded} = $facet->{expanded};
} # facets
}
- # End PROGILONE
}
# warn "connection ", $i-1, ": $size hits";
--
1.7.6.1
More information about the Patches
mailing list