home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / asp / index.asp < prev    next >
Encoding:
Text File  |  2003-09-03  |  2.4 KB  |  91 lines

  1. <%
  2. my $input = $Request->{QueryString}{search} || $Request->{Form}{search};
  3. my $copy = $input;
  4. my %final = &search_words($copy);
  5. my @final = keys %final;
  6.  
  7. $title = "Site Search";
  8. %>
  9.  
  10. <!--#include file=header.inc-->
  11. <center>
  12. <form action=<%=basename($0)%> method=POST>
  13. <input type=text size=30 name=search value="<%=$Server->HTMLEncode($input)%>" maxlength=50>
  14. <input type=submit value=Search>
  15. </form>
  16. </center>
  17.  
  18. <% 
  19. unless(@final) {
  20.     %> No search performed. <%
  21.       $Response->Include('footer.inc');
  22.     $Response->End();
  23. }
  24.  
  25. my($files, $matches) = &search_files(@final);
  26.  
  27. if(keys %$matches) {
  28.   %>
  29.        <b>Matches:</b>
  30.        <tt>
  31.        <%= join(", ", map { "$_: $matches->{$_}" } keys %$matches) %>
  32.        </tt>
  33.        <p>
  34.   <%
  35. } else {
  36.     print "No matches found for your search.";    
  37. }
  38.  
  39. print "<font size=-1>\n";
  40. my $count = 0;
  41. my $final_match = join('|', @final);
  42. for my $file (reverse sort { $files->{$a} <=> $files->{$b} } keys %$files) {
  43.     my $score = $files->{$file};
  44.     $Response->Debug("listing ranked $file");
  45.     my $file_data = $SDB{"FILE:$file"};
  46.     my($title,$summary) = ($file_data->{'title'}, $file_data->{summary});
  47. #    $Response->Debug($file_data);
  48.     unless($title || $summary) {
  49.     $Response->Debug("no data for $file");
  50.     next;
  51.     }
  52.     unless(-e $file) {
  53.     $Response->Debug("file $file is deleted");
  54.     next;
  55.     }   
  56.     
  57.     my $wrap_per_match = 200 / @final;
  58.     my $head_match_size = int($wrap_per_match / 3);
  59.     my $tail_match_size = int($wrap_per_match / 3 * 2);
  60.     my %summary_matches;
  61.     my $summary_match = '<b>...</b> ';
  62.     $summary =~ s/\b(.{0,$head_match_size}\b)($final_match)\b(.{0,$tail_match_size}\b)/
  63.     { 
  64.     unless($summary_matches{lc($2)}++ >= 3) {
  65.         my($head, $mid, $tail) = ($1, $2, $3);
  66.         $head =~ s,\b($final_match)\b,<b>$1<\/b>,sgi;
  67.         $tail =~ s,\b($final_match)\b,<b>$1<\/b>,sgi;
  68.         $summary_match .= "$head<b>$mid<\/b>$tail <b>...<\/b> ";
  69.     }
  70.     '';
  71.     }
  72.     /esgix;
  73.     my $rel_file = $file;
  74.     $rel_file =~ s/^$CONF{FileRoot}\/?//;
  75.     $title ||= $rel_file;
  76.       %>
  77.        <b><%= ++$count %>.</b> 
  78.        <a href="<%= $CONF{SiteRoot}.'/'.$rel_file %>"><%=$title%></a>
  79.        <nobr><i>( Score: <%= $score %> )</i></nobr>
  80.        <br>
  81.        <%= $summary_match %> 
  82.        <br>
  83.        <p>
  84.       <%    
  85.       ;
  86.     $Response->Flush;
  87. }
  88. %>
  89. </font>
  90. <!--#include file=footer.inc-->
  91.