fixing subject link on detail pages and searching API

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
Joshua Ferraro 2007-11-06 16:30:51 -06:00
parent 3fbd25602b
commit 8e01ae8e18
3 changed files with 40 additions and 42 deletions

View File

@ -1790,48 +1790,43 @@ sub GetMarcSubjects {
$mintag = "600";
$maxtag = "611";
}
my @marcsubjects;
my $subject = "";
my $subfield = "";
my $marcsubject;
my @marcsubjcts;
foreach my $field ( $record->fields ) {
foreach my $field ( $record->field('6..' )) {
next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
my @subfields_loop;
my @subfields = $field->subfields();
my $link = "su:";
my $label;
my $flag = 0;
my $authoritysep=C4::Context->preference("authoritysep");
for my $subject_subfield ( @subfields ) {
if (
$marcflavour ne 'MARC21'
and (
($subject_subfield->[0] eq '3') or
($subject_subfield->[0] eq '4') or
($subject_subfield->[0] eq '5')
)
)
{
next;
}
my $code = $subject_subfield->[0];
$label .= $subject_subfield->[1].$authoritysep unless ( $code == 9 );
$link .= " and su-to:".$subject_subfield->[1] unless ( $code == 9 );
if ( $code == 9 ) {
$link = "an:".$subject_subfield->[1];
$flag = 1;
}
elsif ( ! $flag ) {
$link =~ s/ and\ssu-to:$//;
}
}
$label =~ s/$authoritysep$//;
push @marcsubjcts,
{
label => $label,
link => $link
}
}
return \@marcsubjcts;
} #end GetMarcSubjects
my $counter = 0;
my @link_loop;
for my $subject_subfield (@subfields ) {
# don't load unimarc subfields 3,4,5
next if (($marcflavour eq "UNIMARC") and ($subject_subfield->[0] =~ (3|4|5) ) );
my $code = $subject_subfield->[0];
my $value = $subject_subfield->[1];
my $linkvalue = $value;
$linkvalue =~ s/(\(|\))//g;
my $operator = " and " unless $counter==0;
push @link_loop, {link => $linkvalue, operator => $operator };
my $separator = C4::Context->preference("authoritysep") unless $counter==0;
# ignore $9
push @subfields_loop, {code => $code, value => $value, link_loop => \@link_loop, separator => $separator} unless ($subject_subfield->[0] == 9 );
# this needs to be added back in in a way that the template can expose it properly
#if ( $code == 9 ) {
# $link = "an:".$subject_subfield->[1];
# $flag = 1;
#}
$counter++;
}
push @marcsubjects, { MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop };
}
return \@marcsubjects;
} #end getMARCsubjects
=head2 GetMarcAuthors

View File

@ -565,6 +565,7 @@ sub _remove_stopwords {
# otherwise, a french word like "leçon" is splitted in "le" "çon", le is an empty word, we get "çon"
# and don't find anything...
foreach (keys %{C4::Context->stopwords}) {
next if ($_ =~/(and|or|not)/); # don't remove operators
$operand=~ s/\P{IsAlpha}$_\P{IsAlpha}/ /i;
$operand=~ s/^$_\P{IsAlpha}/ /i;
$operand=~ s/\P{IsAlpha}$_$/ /i;
@ -747,6 +748,7 @@ sub buildQuery {
# COMBINE OPERANDS, INDEXES AND OPERATORS
if ( $operands[$i] ) {
warn "OP: $operands[$i]";
my $operand = $operands[$i];
my $index = $indexes[$i];
# if there's no index, don't use one, it will throw a CCL error
@ -755,7 +757,7 @@ sub buildQuery {
# Remove Stopwords
$operand = _remove_stopwords($operand,$index);
warn "OP_SW: $operand";
# Handle Truncation
my ($nontruncated,$righttruncated,$lefttruncated,$rightlefttruncated,$regexpr);
($nontruncated,$righttruncated,$lefttruncated,$rightlefttruncated,$regexpr) = _add_truncation($operand,$index);

View File

@ -92,8 +92,9 @@
<li><strong>Subjects:</strong>
<ul>
<!-- TMPL_LOOP NAME="MARCSUBJCTS" -->
<li><a href="/cgi-bin/koha/catalogue/search.pl?q=<!-- TMPL_VAR NAME="link" ESCAPE="URL"-->"><!-- TMPL_VAR NAME="label" --></a>
</li>
<li><!-- TMPL_LOOP NAME="MARCSUBJECT_SUBFIELDS_LOOP" -->
<!-- TMPL_VAR NAME="separator" --><a title="$<!-- TMPL_VAR NAME="code" --> <!-- TMPL_VAR NAME="value" -->"href="/cgi-bin/koha/catalogue/search.pl?q=<!-- TMPL_LOOP NAME="link_loop" --><!-- TMPL_VAR NAME="operator" -->su:'<!-- TMPL_VAR NAME="link" -->'<!-- /TMPL_LOOP -->"><!-- TMPL_VAR NAME="value" --></a> <!-- /TMPL_LOOP --></li>
<!-- /TMPL_LOOP -->
</ul>
</li>