[Home]WikiPatches/PatchForBetterSearchOutput

UseModWiki | WikiPatches | RecentChanges | Preferences

$ diff usemod092/wiki.pl patchedwiki.pl
861,862c861,864
<   my ($id) = @_;
<   my $name = $id;
---
>   my ($id, $name) = @_;
>   if (!defined($name)) {
>     $name = $id;
>   }
963c965,966
<     $result .= $q->h1($header . &GetSearchLink($id));
---
>     my $shortlink =  &GetSearchLink("$id&shortresult=on", "*");
>     $result .= $q->h1($header . &GetSearchLink($id) . "  $shortlink");
1006a1010,1012
> 
>   # add new shortcut tag here:  $html .= qq(<LINK REL="SHORTCUT ICON" HREF="someicon.ico">\n);
> 
1110a1117,1122
>   my $checked = $q->param('shortresult');
>   my $checkbox = $q->checkbox(
>     -name=>'shortresult',
>     -checked=> ($checked) ? 'checked' : '',
>     -value=>'on',
>     -label=>'short');
1111a1124,1125
>             . "  "
>             . $checkbox
3036c3050,3055
<   &PrintPageList(&SearchTitleAndBody($string));
---
>   my $XSearchDisp = ($q->param('shortresult') eq "on") ? 0 : 1;
>   if ( $XSearchDisp ) { # managed by config file (?)
>     &PrintSearchResults($string,&SearchTitleAndBody($string)) ;
>   } else {
>     &PrintPageList(&SearchTitleAndBody($string));
>   }
3039a3059,3131
> sub PrintSearchResults {
>   my ( $searchstring, @results ) = @_ ;  #  inputs
>   my ( $output ) ;
> 
>   my ( $name ) ;
>   my ( $pageText ) ;
>   my ( $t, $j, $jsnippet, $start, $end ) ;
>   my ( $snippetlen, $maxsnippets ) = ( 50, 3 ) ; #  these seem nice.
>   my $three_points = " . . .  ";
> 
>   print "\n<h2>", ($#results + 1), " pages found:</h2>";
> 
>   foreach $name (@results) {
>     #  get the page, filter it, remove all tags (since we're presenting in
>     #  plaintext, not HTML, a la google(tm)).
>     &OpenPage($name);
>     &OpenDefaultText();
>     $pageText = &QuoteHtml($Text{'text'});
>     $pageText =~ s/$FS//g;  # Remove separators (paranoia)
>     $pageText =~ s/[\s]+/ /g;  #  Shrink whitespace
>     $pageText =~ s/([-_=\\*\\.]){10,}/$1$1$1$1$1/g ; # e.g. shrink "----------"
>     foreach $t (@HtmlPairs, "pre", "nowiki", "code" ) {
>       $pageText =~ s/\<$t(\s[^<>]+?)?\>(.*?)\<\/$t\>/$2/gis;
>     }
>     foreach $t (@HtmlSingle) {
>       $pageText =~ s/\<$t(\s[^<>]+?)?\>//gi;
>     }
> 
>     #  entry header
>     $output = "\n\n" ;
>     $output .= "... "  if ($name =~ m|/|);
>     $output .= "<font size='3'>" . &GetPageLink($name) . "</font><br>\n" ;
> 
>     #  show a snippet from the top of the document
>     $j = index( $pageText, " ", $snippetlen ) ;  #  end on word boundary
>     my $firstText = substr( $pageText, 0, $j );
>     $firstText =~ s/($searchstring)/<b>\1<\/b>/gi ;
>     $output .= "<font size='-1'>" . $firstText . $three_points . "</font>" ;
>     $pageText = substr( $pageText, $j ) ;  #  to avoid rematching
> 
>     #  search for occurrences of searchstring
>     $jsnippet = 0 ;
>     while ( $jsnippet < $maxsnippets
>            &&  $pageText =~ m/($searchstring)/i ) {  #  captures match as $1
>       $jsnippet++ ;  #  paranoid about looping
>       if ( ($j = index( $pageText, $1 )) > -1 ) {  #  get index of match
>         #  get substr containing (start of) match, ending on word boundaries
>         $start = index( $pageText, " ", $j-($snippetlen/2) ) ;
>         $start = 0  if ( $start == -1 ) ;
>         $end = index( $pageText, " ", $j+($snippetlen/2) ) ;
>         $end = length( $pageText )  if ( $end == -1 ) ;
>         $t = substr( $pageText, $start, $end-$start ) ;
>         #  highlight occurrences and tack on to output stream.
>         $t =~ s/($searchstring)/<b>\1<\/b>/gi ;
>         $output .= "<font size='-1'>" . $t . $three_points . "</font>" ;
>         #  truncate text to avoid rematching the same string.
>         $pageText = substr( $pageText, $end ) ;
>       }
>     }
> 
>     #  entry trailer
>     $output .= "<br><i><font size=-1>"
>         . int((length($pageText)/1024)+1) . "K - last updated "
>         . &TimeToText($Section{ts}) . " by "
>         . &GetAuthorLink( $Section{'host'}, $Section{'username'},
>                          $Section{'id'} )
>         . "</font></i><br><br>" ;
> 
>     print $output ;
> 
>   }
> }
> 

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited April 30, 2002 4:51 pm by 212.86.210.xxx (diff)
Search: