/[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 85 by dpavlin, Sun Aug 29 18:26:58 2004 UTC revision 86 by dpavlin, Mon Aug 30 11:16:39 2004 UTC
# Line 12  use Data::Pageset; Line 12  use Data::Pageset;
12    
13  sub get_snippet {  sub get_snippet {
14          my $context_chars = 100;          my $context_chars = 100;
         my $max_desc = 16384;   # 16k to filter  
15    
16          my $desc = shift || return '';          my $desc = shift || return '';
         $desc = substr($desc,0,$max_desc) if (length($desc) > $max_desc);  
17          $desc = e($desc);          $desc = e($desc);
18    
19          # test if $desc contains any of our query words          # test if $desc contains any of our query words
20          my @snips;          my @snips;
21    
22          my @colors = qw{#ffff66 #a0ffff #99ff99 #ff9999 #ff66ff};          my @colors = qw{#ffff66 #a0ffff #99ff99 #ff9999 #ff66ff};
23    
24          my $i = 0;          # construct regex
25            my $re = qq/^.*?(.{$context_chars}?)(\Q/ . join("|",@_) .
26                    qq/\E)(.{$context_chars})/;
27    
28          for my $q (@_) {          while ($desc =~ s/$re//si) {
29                  if ($desc =~ m/(.*?)(\Q$q\E)(.*)/si) {                  my ($bef,$qm,$af) = ($1, $2, $3);
                         my $bef = $1;  
                         my $qm = $2;  
                         my $af = $3;  
                         $bef = substr $bef, -$context_chars;  
                         $af = substr $af, 0, $context_chars;  
30                                                    
31                          # no partial words...                  # no partial words...
32                          $af =~ s,^\S+\s+|\s+\S+$,,gs;                  $bef =~ s,^\S+\s+|\s+\S+$,,gs;
33                          $bef =~ s,^\S+\s+|\s+\S+$,,gs;                  $af =~ s,^\S+\s+|\s+\S+$,,gs;
34    
35                          push(@snips, "$bef <span style=\"background:".$colors[$i]."; color:black;\">$qm</span> $af");                  push @snips, "$bef $qm $af";
                         $i++;  
                         $i = 0 if ($i > $#colors);  
                 }  
36          }          }
37    
38          my $ellip = ' ... ';          my $ellip = ' ... ';
39          my $snippet = $ellip. join($ellip, @snips) . $ellip if (@snips);          my $snippet;
40              
41            if (@snips) {
42                    $snippet = $ellip. join($ellip, @snips) . $ellip;
43            } else {
44                    return '';
45            }
46    
47            # color offset
48            my $i = 0;
49    
50            foreach my $w (@_) {
51                    $snippet =~ s,(\Q$w\E),<span style="background: $colors[$i]; color:black;">$1</span>,gsi;
52                    $i++;
53                    $i = 0 if ($i > $#colors);
54            }
55    
56          return $snippet;          return $snippet;
57  }  }
58    
# Line 109  $path .= '"'.join('*" or "',param('path' Line 118  $path .= '"'.join('*" or "',param('path'
118  my %path_label;  my %path_label;
119  my @path_name;  my @path_name;
120  foreach (@{$config->{paths}->{path}}) {  foreach (@{$config->{paths}->{path}}) {
   
 print STDERR "##: $_->{limit}",x($_->{content}),"\n";  
121          push @path_name,x($_->{limit});          push @path_name,x($_->{limit});
122          $path_label{$_->{limit}} = x($_->{content});          $path_label{$_->{limit}} = x($_->{content});
123  }  }
# Line 143  if (param('search')) { Line 150  if (param('search')) {
150          my $s;          my $s;
151          # re-write query from +/- to and/and not          # re-write query from +/- to and/and not
152    
153            my @s_elem;
154    
155          my $search = param('search');          my $search = param('search');
156          my $s_phrase = "";  
157            # strip spaces
158            $search =~ s/^\s+//;
159            $search =~ s/\s+$//;
160            # fixup search string
161            $search=~tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/;     # 1250 -> iso8859-2
162            $search=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/;
163    
164            # extract phrases and put them first
165          while ($search =~ s/\s*("[^"]+")\s*/ /) {          while ($search =~ s/\s*("[^"]+")\s*/ /) {
166                  $s .= "$1 ";                  $s .= "$1 ";
167                    push @s_elem, $1;
168          }          }
         $search =~ s/^\s+//;  
         $search =~ s/\s+$//;  
169    
170          my %words;          my %words;
171    
# Line 168  if (param('search')) { Line 184  if (param('search')) {
184                          } else {                          } else {
185                                  $s.="$2* ";                                  $s.="$2* ";
186                          }                          }
187                            push @s_elem, $2;
188                  } else {                  } else {
189                          if (@spellings && !param('no_affix')) {                          if (@spellings && !param('no_affix')) {
190                                  my $w = $_; $w =~ s/[\*\s]+//g;                                  my $w = $_; $w =~ s/[\*\s]+//g;
                                 #$s.="(".join("* or ",$spelling_alt->alternatives($w))."*) ";  
191                                  my $or="";                                  my $or="";
192                                  foreach my $spelling_alt (@spellings) {                                  foreach my $spelling_alt (@spellings) {
193                                          $s.="$or(".join("* or ",$spelling_alt->alternatives($w))."*) ";                                          $s.="$or(".join("* or ",$spelling_alt->alternatives($w))."*) ";
# Line 180  if (param('search')) { Line 196  if (param('search')) {
196                          } else {                          } else {
197                                  $s.="$_* ";                                  $s.="$_* ";
198                          }                          }
199                            push @s_elem, $_;
200                  }                  }
201          }          }
202    
203          # fixup search string          # fix multiple stars
         $s=~tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/;  # 1250 -> iso8859-2  
         $s=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/;  
204          $s=~s/\*\*+/*/g;          $s=~s/\*\*+/*/g;
205    
206          # limit to some path          # limit to some path
# Line 259  if (param('search')) { Line 274  if (param('search')) {
274                          if ($prop =~ m/swishdescription/) {                          if ($prop =~ m/swishdescription/) {
275                                  my $tmp = get_snippet(                                  my $tmp = get_snippet(
276                                          $result->Property($prop),                                          $result->Property($prop),
277                                          split(/\s+/,$search)                                          @s_elem,
278                                  );                                  );
279                                                                    
280                                  push @arr, $tmp;                                  push @arr, $tmp;

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

  ViewVC Help
Powered by ViewVC 1.1.26