fix for bug 1658: <span class="term"> in search terms

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>
This commit is contained in:
Joshua Ferraro 2007-12-18 01:34:29 -06:00
parent 592a764ad3
commit 7a3e596813
2 changed files with 19 additions and 9 deletions

View 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;

View 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