/[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 79 by dpavlin, Sat Apr 17 18:41:21 2004 UTC revision 80 by dpavlin, Sat May 22 18:33:33 2004 UTC
# Line 16  Text::Iconv->raise_error(0);     # Conve Line 16  Text::Iconv->raise_error(0);     # Conve
16  my $config=XMLin(undef,  my $config=XMLin(undef,
17  #               keyattr => { label => "value" },  #               keyattr => { label => "value" },
18                  forcecontent => 0,                  forcecontent => 0,
19                    ForceArray => [ 'path' ],
20          );          );
21    
22  my $from_utf8 = Text::Iconv->new('UTF8', $config->{charset});  my $from_utf8 = Text::Iconv->new('UTF8', $config->{charset});
# Line 40  my @spellings; Line 41  my @spellings;
41  # FIX: doesn't work very well  # FIX: doesn't work very well
42  if ($config->{findaffix}) {  if ($config->{findaffix}) {
43          foreach my $findaffix (split(/[, ]+/,x($config->{findaffix}))) {          foreach my $findaffix (split(/[, ]+/,x($config->{findaffix}))) {
44                    next if (! -f $findaffix);
45                  my $spelling_alt = new Lingua::Spelling::Alternative;                  my $spelling_alt = new Lingua::Spelling::Alternative;
46                  $spelling_alt->load_findaffix($findaffix);                  $spelling_alt->load_findaffix($findaffix);
47                  push @spellings,$spelling_alt;                  push @spellings,$spelling_alt;
# Line 47  if ($config->{findaffix}) { Line 49  if ($config->{findaffix}) {
49  }  }
50  if ($config->{affix}) {  if ($config->{affix}) {
51          foreach my $affix (split(/[, ]+/,x($config->{affix}))) {          foreach my $affix (split(/[, ]+/,x($config->{affix}))) {
52                    next if (! -f $affix);
53                  my $spelling_alt = new Lingua::Spelling::Alternative;                  my $spelling_alt = new Lingua::Spelling::Alternative;
54                  $spelling_alt->load_affix($affix);                  $spelling_alt->load_affix($affix);
55                  push @spellings,$spelling_alt;                  push @spellings,$spelling_alt;
# Line 170  if (param('search')) { Line 173  if (param('search')) {
173                  $hit_fmt = x($config->{hit}) if (x($config->{hit}));                  $hit_fmt = x($config->{hit}) if (x($config->{hit}));
174          }          }
175    
 #       my $sh = SWISH->connect('Fork',  
 #               prog     => x($config->{prog}),  
 #               indexes  => x($config->{index}),  
 #               results  => sub {  
 #                       my ($sh,$hit) = @_;  
 #  
 #                       if ($config->{url}) {  
 #                               printf ($hit_fmt ,"http://".virtual_host().x($config->{url}).$hit->swishdocpath,e($hit->swishtitle) || 'untitled',$hit->swishrank, map($hit->$_, @properties));  
 #                       } else {  
 #                               printf ($hit_fmt ,$hit->swishdocpath,e($hit->swishtitle) || 'untitled',$hit->swishrank, map($hit->$_, @properties) );  
 #  
 #                       }  
 #  
 ##                      print $_[1]->as_string,"<br>\n";  
 ##                      my @fields = $hit->field_names;  
 ##                      print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields;  
 #               },  
 #               maxhits => param('max_hits') || $max_hits,  
 #               \%params,  
 #       );  
 #  
 #       die $SWISH::errstr unless $sh;  
 #  
 #       $hits = $sh->query($s);  
 #  
 #       if ($hits && $hits > 0) {  
 #               print p,hr;  
 #               printf (x($config->{text}->{hits}),$hits,param('max_hits') || $max_hits,$s);  
 #       } else {  
 #               print p;  
 #               printf (x($config->{text}->{no_hits}),$s,$sh->errstr);  
 #       }  
 #       if ($hits && $hits > 0) {  
 #               print p,hr;  
 #               printf (x($config->{text}->{hits}),$hits,param('max_hits') || $max_hits,$s);  
 #       } else {  
 #               print p;  
 #               printf (x($config->{text}->{no_hits}),$s,$sh->errstr);  
 #       }  
   
176          my $swish = SWISH::API->new($config->{index});          my $swish = SWISH::API->new($config->{index});
   
177          $swish->AbortLastError if $swish->Error;          $swish->AbortLastError if $swish->Error;
   
178          my $results = $swish->Query($s);          my $results = $swish->Query($s);
   
179          my $hits = $results->Hits;          my $hits = $results->Hits;
180    
181    
   
182          # build pager          # build pager
183          my $current_page = param('page') || 1;          my $current_page = param('page') || 1;
184    
# Line 242  if (param('search')) { Line 201  if (param('search')) {
201                  printf (x($config->{text}->{hits}),$i,$results->Hits,$s);                  printf (x($config->{text}->{hits}),$i,$results->Hits,$s);
202          }          }
203    
204            my %path2title;
205            use Data::Dumper;
206            foreach my $p (@{$config->{path2title}->{path}}) {
207                    $path2title{$p->{dir}} = $p->{content};
208            }
209    
210          for(my $i=$pager->first; $i<=$pager->last; $i++) {          for(my $i=$pager->first; $i<=$pager->last; $i++) {
211    
# Line 263  if (param('search')) { Line 227  if (param('search')) {
227                  my $rank = $result->Property("swishrank");                  my $rank = $result->Property("swishrank");
228                  my $host = $result->Property("swishdocpath");                  my $host = $result->Property("swishdocpath");
229                  $host = "http://".virtual_host().x($config->{url}).$result->Property("swishdocpath") if ($config->{url});                  $host = "http://".virtual_host().x($config->{url}).$result->Property("swishdocpath") if ($config->{url});
230    
231                    foreach my $p (keys %path2title) {
232                            if ($host =~ m/$p/i) {
233                                    $title =~ s/$path2title{$p}\s*[:-]+\s*//;
234                                    $title = $path2title{$p}." :: ".$title;
235                                    last;
236                            }
237                    }
238    
239                  print $tr_pre,$i,". ";                  print $tr_pre,$i,". ";
240                  # print collection name which is not link                  # print collection name which is not link
241                  if ($title =~ s/^(.+? :: )//) {                  if ($title =~ s/^(.+? :: )//) {
242                          print $1;                          print $1;
243                  }                  }
244    
245                  printf($hit_fmt, $host, $title || 'untitled', $rank, @arr);                  printf($hit_fmt, $host, $title || 'untitled', $rank, @arr);
246                  print $tr_post;                  print $tr_post;
247    

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

  ViewVC Help
Powered by ViewVC 1.1.26