fix for bug 1658: <span class="term"> in search terms
authorJoshua Ferraro <jmf@liblime.com>
Tue, 18 Dec 2007 07:34:29 +0000 (01:34 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Tue, 18 Dec 2007 10:47:16 +0000 (04:47 -0600)
Also, adds google-style search query highlighting anywhere
in the record

Need to check if this fix is in the OPAC

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Search.pm
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl

index a108525..a82e8c2 100644 (file)
@@ -1052,19 +1052,28 @@ sub searchResults {
         }
         # add spans to search term in results for search term highlighting
         # save a native author, for the <a href=search.lq=<!--tmpl_var name="author"-->> link
+               my $searchhighlightblob;
+               for my $highlight_field ($marcrecord->fields) {
+                       next if $highlight_field->tag() =~ /(^00)/; # skip fixed fields
+                       my $match;
+                       my $field = $highlight_field->as_string();
+                       for my $term ( keys %$span_terms_hashref ) {
+                               if (($field =~ /$term/) && (length($term) > 3)) {
+                                       $field =~ s/$term/<span class=\"term\">$&<\/span>/gi;
+                                       $match++;
+                               }
+                       }
+                       $searchhighlightblob .= $field." ... " if $match;
+               }
+               $oldbiblio->{'searchhighlightblob'} = $searchhighlightblob;
+
         $oldbiblio->{'author_nospan'} = $oldbiblio->{'author'};
-        foreach my $term ( keys %$span_terms_hashref ) {
+        for my $term ( keys %$span_terms_hashref ) {
             my $old_term = $term;
             if ( length($term) > 3 ) {
-                $term =~ s/(.*=|\)|\(|\+|\.|\?|\[|\])//g;
-                $term =~ s/\\//g;
-                $term =~ s/\*//g;
-
-                #FIXME: is there a better way to do this?
+                $term =~ s/(.*=|\)|\(|\+|\.|\?|\[|\]|\\|\*)//g;
                 $oldbiblio->{'title'} =~ s/$term/<span class=\"term\">$&<\/span>/gi;
-                $oldbiblio->{'subtitle'} =~
-                  s/$term/<span class=\"term\">$&<\/span>/gi;
-
+                $oldbiblio->{'subtitle'} =~ s/$term/<span class=\"term\">$&<\/span>/gi;
                 $oldbiblio->{'author'} =~ s/$term/<span class=\"term\">$&<\/span>/gi;
                 $oldbiblio->{'publishercode'} =~ s/$term/<span class=\"term\">$&<\/span>/gi;
                 $oldbiblio->{'place'} =~ s/$term/<span class=\"term\">$&<\/span>/gi;
index 85b01c5..311e8a6 100644 (file)
@@ -290,6 +290,7 @@ $(window).load(function() {
                                                                                <!-- TMPL_VAR name="description" -->
                                         <!-- TMPL_IF name="timestamp" --> <i>(modified on <!-- TMPL_VAR name="timestamp" -->)</i><!-- /TMPL_IF -->
                                     </p>
+                                                                       <p><!-- TMPL_VAR NAME="searchhighlightblob" --></p>
                                 <!-- /TMPL_IF -->
                                                                  <!-- TMPL_IF NAME="norequests" -->
                                         No holds allowed