fixing subject link on detail pages and searching API
authorJoshua Ferraro <jmf@liblime.com>
Tue, 6 Nov 2007 22:30:51 +0000 (16:30 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Wed, 7 Nov 2007 14:24:06 +0000 (08:24 -0600)
Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Biblio.pm
C4/Search.pm
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl

index d5a01a1..451e072 100644 (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
 
index 70ed90d..729529d 100644 (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);
index 4ee7757..0893cb6 100644 (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>