Perlfect Solutions
 

[Perlfect-search] Result list term emhasize

Fini perlfect-search@perlfect.com
Thu, 6 Mar 2003 11:46:18 +0100 (MET)
Hi all!

We have pages about programming where functions are refered to by
"funname()". If you search for "funname" this will not be highlighted
in the result summary list's context examples.

Guilty part is term_emphasize(). There is also the following:
  # TODO?: foo bar -- "foo" will not be emphasized

To correct both problems, just change the split() and join() in that
function. The split should be (according to the comments) on word
boundaries, but not on embedded entities. Entity   should be
treated as whitespace. The split term results to /([^\w&;]| )/.
The join term must be '' in that case.

Another bug is that searching for 'funname().' does only search for
'funname', but the highlighting tries to highlight 'funname().' only.
So the $term is stripped to bare word characters as the search term.

I appended a diff against 3.31 (search.pl r1.95).


Thanks for the great perlfect search!


Cheers,

  Fini


--- search.pl.orig      Thu Mar  6 11:35:08 2003
+++ search.pl   Thu Mar  6 11:38:04 2003
@@ -716,10 +716,11 @@
   my $term = $_[1];
   # "H�user" also matches "Hauser" so be fair and emphasize that, too:
   my $term_no_accents = lc(remove_accents($term));
+  $term_no_accents =~ s/\W//g;
   # Emphasize the term. Using a RegEx with \b is not enough, as the term may
   # contain "&" which would be taken as a word boundary:
   # TODO?: foo bar -- "foo" will not be emphasized
-  my @str_array = split(" ", $str);
+  my @str_array = split(/([^\w&;]| )/, $str);
   foreach $term_in_str (@str_array) {
     my $term_in_str_compare = $term_in_str;
     $term_in_str_compare =~ s/[$punct]//g;
@@ -733,7 +734,7 @@
       $term_in_str =~ s/([$punct]+)<\/strong>/<\/strong>$1/;
     }
   }
-  return join(" ", @str_array);
+  return join('', @str_array);
 }

 sub stem {