/[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 80 by dpavlin, Sat May 22 18:33:33 2004 UTC revision 87 by dpavlin, Mon Aug 30 16:59:17 2004 UTC
# Line 9  use Lingua::Spelling::Alternative; Line 9  use Lingua::Spelling::Alternative;
9  use Text::Iconv;  use Text::Iconv;
10  use Data::Pageset;  use Data::Pageset;
11    
12    sub get_snippet {
13    
14            # maximum length of context in characters
15            my $cc = 50;
16    
17            my $desc = shift || return '';
18            $desc = e($desc);
19    
20            # sort words from longer to shorter (for hilighting later)
21            my @words = sort { length($b) <=> length($a) } @_;
22    
23            # colors to highlite
24            my @colors = qw{#ffff66 #a0ffff #99ff99 #ff9999 #ff66ff};
25    
26            # construct regex
27            my $re = qq/^(.*?\\b)(/ . join('|', @words) . qq/)/;
28    
29            my $ellip = ' ... ';
30            my $snippet = '';
31    
32    #print "<ul>";
33    
34            while ($desc =~ s/$re//si) {
35                    my ($foo, $match) = ($1,$2);
36    
37    #print "<br>desc: <small>$desc</small>\n";
38    #print "<br>foo: <small>$foo<b>$match</b></small>\n";
39    
40                    if (length($foo) < $cc * 2) {
41                            $snippet .= $foo . $match;
42                    } else {
43    
44                            if ($foo =~ m/^(.{0,$cc})(\s.*?\s|\s|)?(.{0,$cc})$/) {
45    
46    #       print "<li><small>$snippet</small><br>
47    #       ",length($1),": <i>$1</i><br>
48    #       ",length($2),": <span style=\"color:grey\">$2</span><br>
49    #       ",length($3),": <i>$3</i><br>
50    #       <b>$match</b>\n";
51    
52                                    if ($snippet) {
53                                            $snippet .= $1 . $ellip . $3 . $match;
54                                    } else {
55                                            $snippet = $ellip . $3 . $match ;
56                                    }
57    
58                            } else {
59    #                               print "<li> <big>SKIP</big> $foo\n";
60                                    print STDERR "this shouldn't happen!\n";
61                            }
62    
63                    }
64    
65            }
66    #print "</ul>";
67    
68            # color offset
69            my $i = 0;
70    
71            foreach my $w (@words) {
72                    $snippet =~ s,(\b\Q$w\E),<span style="background: $colors[$i]; color:black;">$1</span>,gsi;
73                    $i++;
74                    $i = 0 if ($i > $#colors);
75            }
76    
77            $snippet .= $ellip if ($snippet);
78    
79            return $snippet;
80    }
81    
82  # for pager  # for pager
83  my $pages_per_set = 20;  my $pages_per_set = 20;
84    
# Line 65  foreach (@{$config->{labels}->{label}}) Line 135  foreach (@{$config->{labels}->{label}})
135          $labels{$_->{value}} = x($_->{content});          $labels{$_->{value}} = x($_->{content});
136  }  }
137    
138  my $path = param('path');       # limit to this path  my $path;
139    # limit to this path
140    $path .= '"'.join('*" or "',param('path')).'*"' if (param('path'));
141  my %path_label;  my %path_label;
142  my @path_name;  my @path_name;
143  foreach (@{$config->{paths}->{path}}) {  foreach (@{$config->{paths}->{path}}) {
   
 print STDERR "##: $_->{limit}",x($_->{content}),"\n";  
144          push @path_name,x($_->{limit});          push @path_name,x($_->{limit});
145          $path_label{$_->{limit}} = x($_->{content});          $path_label{$_->{limit}} = x($_->{content});
146  }  }
# Line 93  print checkbox(-name=>'no_properties', - Line 163  print checkbox(-name=>'no_properties', -
163  if (@path_name) {  if (@path_name) {
164          print br,x($config->{text}->{limit});          print br,x($config->{text}->{limit});
165          print popup_menu(-name=>'path',-values=>\@path_name,-labels=>\%path_label,-default=>$path);          print popup_menu(-name=>'path',-values=>\@path_name,-labels=>\%path_label,-default=>$path);
166    } elsif (param('path')) {
167            print hidden(-name=>'path',-values=>param('path'));
168  }  }
169  print end_form,hr;  print end_form,hr;
170    
# Line 101  if (param('search')) { Line 173  if (param('search')) {
173          my $s;          my $s;
174          # re-write query from +/- to and/and not          # re-write query from +/- to and/and not
175    
176            my @s_elem;
177    
178          my $search = param('search');          my $search = param('search');
179          my $s_phrase = "";  
180            # strip spaces
181            $search =~ s/^\s+//;
182            $search =~ s/\s+$//;
183            # fixup search string
184            $search=~tr/¹ð¾èæ©Ð®ÈÆ/¹ð¾èæ©Ð®ÈÆ/;     # 1250 -> iso8859-2
185            $search=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/;
186    
187            # extract phrases and put them first
188          while ($search =~ s/\s*("[^"]+")\s*/ /) {          while ($search =~ s/\s*("[^"]+")\s*/ /) {
189                  $s .= "$1 ";                  $s .= "$1 ";
190                    push @s_elem, $1;
191          }          }
         $search =~ s/^\s+//;  
         $search =~ s/\s+$//;  
192    
193          my %words;          my %words;
194    
# Line 126  if (param('search')) { Line 207  if (param('search')) {
207                          } else {                          } else {
208                                  $s.="$2* ";                                  $s.="$2* ";
209                          }                          }
210                            push @s_elem, $2;
211                  } else {                  } else {
212                          if (@spellings && !param('no_affix')) {                          if (@spellings && !param('no_affix')) {
213                                  my $w = $_; $w =~ s/[\*\s]+//g;                                  my $w = $_; $w =~ s/[\*\s]+//g;
                                 #$s.="(".join("* or ",$spelling_alt->alternatives($w))."*) ";  
214                                  my $or="";                                  my $or="";
215                                  foreach my $spelling_alt (@spellings) {                                  foreach my $spelling_alt (@spellings) {
216                                          $s.="$or(".join("* or ",$spelling_alt->alternatives($w))."*) ";                                          $s.="$or(".join("* or ",$spelling_alt->alternatives($w))."*) ";
# Line 138  if (param('search')) { Line 219  if (param('search')) {
219                          } else {                          } else {
220                                  $s.="$_* ";                                  $s.="$_* ";
221                          }                          }
222                            push @s_elem, $_;
223                  }                  }
224          }          }
225    
226          # fixup search string          # fix multiple stars
         $s=~tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/;  # 1250 -> iso8859-2  
         $s=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/;  
227          $s=~s/\*\*+/*/g;          $s=~s/\*\*+/*/g;
228    
229          # limit to some path          # limit to some path
230          $s = "swishdocpath=(\"*$path*\") and $s" if ($path);          $s = "swishdocpath=($path) and $s" if ($path);
231    
232          my %params;     # optional parametars for swish          my %params;     # optional parametars for swish
233    
234          # default format for output          # default format for output
235          my $hit_fmt = "<a href=\"%s\">%s</a> [%s]<br>\n";          my $hit_fmt = "<a href=\"%s\">%s</a> [%s]<br>\n";
236    
         # output start of table  
         print qq{  
 <table border="0">  
         };  
         # html before and after each hit  
         my $tr_pre = qq{  
 <tr><td>  
         };  
         my $tr_post = qq{  
 </td></tr>  
         };  
   
237          if (@properties) {          if (@properties) {
238                  $hit_fmt = x($config->{hit}) if (! param('no_properties'));                  $hit_fmt = x($config->{hit}) if (! param('no_properties'));
239                  $params{properties} = \@properties;                  $params{properties} = \@properties;
# Line 202  if (param('search')) { Line 270  if (param('search')) {
270          }          }
271    
272          my %path2title;          my %path2title;
         use Data::Dumper;  
273          foreach my $p (@{$config->{path2title}->{path}}) {          foreach my $p (@{$config->{path2title}->{path}}) {
274                  $path2title{$p->{dir}} = $p->{content};                  $path2title{$p->{dir}} = $p->{content};
275          }          }
276    
277            # output start of table
278            print qq{
279    <table border="0">
280            };
281            # html before and after each hit
282            my $tr_pre = qq{
283    <tr><td>
284            };
285            my $tr_post = qq{
286    </td></tr>
287            };
288    
289          for(my $i=$pager->first; $i<=$pager->last; $i++) {          for(my $i=$pager->first; $i<=$pager->last; $i++) {
290    
291                  my $result = $results->NextResult;                  my $result = $results->NextResult;
292                  last if (! $result);                  last if (! $result);
293    
294                  my @arr;                  my @arr;
295    
296                  foreach my $prop (@properties) {                  foreach my $prop (@properties) {
297                          if ($prop =~ m/swishdescription/) {                          if ($prop =~ m/swishdescription/) {
298                                  my $tmp = $result->Property($prop);                                  my $tmp = get_snippet(
299                                  $tmp =~ s/<[^>]+>//g;                                          $result->Property($prop),
300                                            @s_elem,
301                                    );
302                                    
303                                  push @arr, $tmp;                                  push @arr, $tmp;
304                          } else {                          } else {
305                                  push @arr, $result->Property($prop);                                  push @arr, $result->Property($prop);

Legend:
Removed from v.80  
changed lines
  Added in v.87

  ViewVC Help
Powered by ViewVC 1.1.26