/[swish]/trunk/html/swish.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/html/swish.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 86 by dpavlin, Mon Aug 30 11:16:39 2004 UTC revision 89 by dpavlin, Tue Aug 31 09:04:15 2004 UTC
# Line 8  use XML::Simple; Line 8  use XML::Simple;
8  use Lingua::Spelling::Alternative;  use Lingua::Spelling::Alternative;
9  use Text::Iconv;  use Text::Iconv;
10  use Data::Pageset;  use Data::Pageset;
11    use FormatResult;
   
 sub get_snippet {  
         my $context_chars = 100;  
   
         my $desc = shift || return '';  
         $desc = e($desc);  
   
         # test if $desc contains any of our query words  
         my @snips;  
   
         my @colors = qw{#ffff66 #a0ffff #99ff99 #ff9999 #ff66ff};  
   
         # construct regex  
         my $re = qq/^.*?(.{$context_chars}?)(\Q/ . join("|",@_) .  
                 qq/\E)(.{$context_chars})/;  
   
         while ($desc =~ s/$re//si) {  
                 my ($bef,$qm,$af) = ($1, $2, $3);  
                           
                 # no partial words...  
                 $bef =~ s,^\S+\s+|\s+\S+$,,gs;  
                 $af =~ s,^\S+\s+|\s+\S+$,,gs;  
   
                 push @snips, "$bef $qm $af";  
         }  
   
         my $ellip = ' ... ';  
         my $snippet;  
           
         if (@snips) {  
                 $snippet = $ellip. join($ellip, @snips) . $ellip;  
         } else {  
                 return '';  
         }  
   
         # color offset  
         my $i = 0;  
   
         foreach my $w (@_) {  
                 $snippet =~ s,(\Q$w\E),<span style="background: $colors[$i]; color:black;">$1</span>,gsi;  
                 $i++;  
                 $i = 0 if ($i > $#colors);  
         }  
   
         return $snippet;  
 }  
12    
13  # for pager  # for pager
14  my $pages_per_set = 20;  my $pages_per_set = 20;
# Line 150  if (param('search')) { Line 104  if (param('search')) {
104          my $s;          my $s;
105          # re-write query from +/- to and/and not          # re-write query from +/- to and/and not
106    
107          my @s_elem;          my @s_highlite;
108    
109          my $search = param('search');          my $search = param('search');
110    
# Line 158  if (param('search')) { Line 112  if (param('search')) {
112          $search =~ s/^\s+//;          $search =~ s/^\s+//;
113          $search =~ s/\s+$//;          $search =~ s/\s+$//;
114          # fixup search string          # fixup search string
115          $search=~tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/;     # 1250 -> iso8859-2          $search=~tr/¹ð¾èæ©Ð®ÈÆ/¹ð¾èæ©Ð®ÈÆ/;     # 1250 -> iso8859-2
116          $search=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/;          $search=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/;
117    
118          # extract phrases and put them first          # extract phrases and put them first
119          while ($search =~ s/\s*("[^"]+")\s*/ /) {          while ($search =~ s/\s*("[^"]+")\s*/ /) {
120                  $s .= "$1 ";                  $s .= "$1 ";
121                  push @s_elem, $1;                  push @s_highlite, $1;
122          }          }
123    
124          my %words;          my %words;
# Line 184  if (param('search')) { Line 138  if (param('search')) {
138                          } else {                          } else {
139                                  $s.="$2* ";                                  $s.="$2* ";
140                          }                          }
141                          push @s_elem, $2;                          push @s_highlite, $2 if ($1 ne "-");
142                  } else {                  } else {
143                          if (@spellings && !param('no_affix')) {                          if (@spellings && !param('no_affix')) {
144                                  my $w = $_; $w =~ s/[\*\s]+//g;                                  my $w = $_; $w =~ s/[\*\s]+//g;
# Line 196  if (param('search')) { Line 150  if (param('search')) {
150                          } else {                          } else {
151                                  $s.="$_* ";                                  $s.="$_* ";
152                          }                          }
153                          push @s_elem, $_;                          push @s_highlite, $_;
154                  }                  }
155          }          }
156    
# Line 272  if (param('search')) { Line 226  if (param('search')) {
226    
227                  foreach my $prop (@properties) {                  foreach my $prop (@properties) {
228                          if ($prop =~ m/swishdescription/) {                          if ($prop =~ m/swishdescription/) {
229                                  my $tmp = get_snippet(                                  my $tmp = FormatResult::get_snippet(
230                                          $result->Property($prop),                                          e($result->Property($prop)),
231                                          @s_elem,                                          @s_highlite,
232                                  );                                  );
233                                                                    
234                                  push @arr, $tmp;                                  push @arr, $tmp;

Legend:
Removed from v.86  
changed lines
  Added in v.89

  ViewVC Help
Powered by ViewVC 1.1.26