/[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 21 by dpavlin, Tue Mar 18 20:20:11 2003 UTC revision 29 by dpavlin, Mon Mar 24 09:04:57 2003 UTC
# Line 19  sub x { Line 19  sub x {
19          return $from_utf8->convert($_[0]);          return $from_utf8->convert($_[0]);
20  }  }
21    
22  use Data::Dumper;  # Escape <, >, & and ", and to produce valid XML
23  #print Dumper($config);  my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');  
24    my $escape_re  = join '|' => keys %escape;
25    sub e {
26            my $out;
27            foreach my $v (@_) {
28                    $v =~ s/($escape_re)/$escape{$1}/g;
29                    $out .= $v;
30            }
31            return $out;
32    }
33    
34  my $spelling_alt;  my $spelling_alt;
35  # FIX: doesn't work very well  # FIX: doesn't work very well
# Line 41  foreach (@{$config->{labels}->{label}}) Line 50  foreach (@{$config->{labels}->{label}})
50          $labels{$_->{value}} = x($_->{content});          $labels{$_->{value}} = x($_->{content});
51  }  }
52    
53    my $path = param('path');       # limit to this path
54    my %path_label;
55    my @path_name;
56    foreach (@{$config->{paths}->{path}}) {
57            push @path_name,x($_->{limit});
58            $path_label{$_->{limit}} = x($_->{content});
59    }
60    
61  if ($config->{charset}) {  if ($config->{charset}) {
62          print header(-charset=>x($config->{charset}));          print header(-charset=>x($config->{charset}));
63  } else {  } else {
# Line 53  print x($config->{text}->{documents}); Line 70  print x($config->{text}->{documents});
70  print textfield('search');  print textfield('search');
71  print submit(-value=> x($config->{text}->{submit}));  print submit(-value=> x($config->{text}->{submit}));
72  print checkbox(-name=>'no_affix', -checked=>0, -label=>x($config->{text}->{no_spell})) if ($spelling_alt);  print checkbox(-name=>'no_affix', -checked=>0, -label=>x($config->{text}->{no_spell})) if ($spelling_alt);
73    if (@path_name) {
74            print br,x($config->{text}->{limit});
75            print popup_menu(-name=>'path',-values=>\@path_name,-labels=>\%path_label,-default=>$path);
76    }
77  print end_form,hr;  print end_form,hr;
78    
79  if (param('search')) {  if (param('search')) {
# Line 95  if (param('search')) { Line 116  if (param('search')) {
116          $s=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/;          $s=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/;
117          $s=~s/\*\*+/*/g;          $s=~s/\*\*+/*/g;
118    
119            # limit to some path
120            $s = "swishdocpath=(\"$path\") and $s" if ($path);
121    
122            my %params;     # optional parametars for swish
123    
124          my @properties = split(/\s+/,x($config->{properties}));          my @properties = split(/\s+/,x($config->{properties}));
125            $params{properties} = \@properties if (@properties);
126    
127          my $sh = SWISH->connect('Fork',          my $sh = SWISH->connect('Fork',
128                  prog     => x($config->{prog}),                  prog     => x($config->{prog}),
129                  indexes  => x($config->{index}),                  indexes  => x($config->{index}),
                 properties  => \@properties,  
130                  results  => sub {                  results  => sub {
131                          my ($sh,$hit) = @_;                          my ($sh,$hit) = @_;
132    
# Line 108  if (param('search')) { Line 134  if (param('search')) {
134                                  "<a href=\"%s\">%s</a> [%s]<br>\n";                                  "<a href=\"%s\">%s</a> [%s]<br>\n";
135    
136                          if ($config->{url}) {                          if ($config->{url}) {
137                                  printf ($hit_fmt ,"http://".virtual_host().x($config->{url}).$hit->swishdocpath,$hit->swishtitle || 'untitled',$hit->swishrank);                                  printf ($hit_fmt ,"http://".virtual_host().x($config->{url}).$hit->swishdocpath,e($hit->swishtitle) || 'untitled',$hit->swishrank);
138                          } else {                          } else {
139                                  printf ($hit_fmt ,$hit->swishdocpath,$hit->swishtitle || 'untitled',$hit->swishrank, map($hit->$_, @properties) );                                  printf ($hit_fmt ,$hit->swishdocpath,e($hit->swishtitle) || 'untitled',$hit->swishrank, map($hit->$_, @properties) );
140    
141                          }                          }
142    
# Line 119  if (param('search')) { Line 145  if (param('search')) {
145  #                       print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields;  #                       print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields;
146                  },                  },
147                  maxhits => param('max_hits') || $max_hits,                  maxhits => param('max_hits') || $max_hits,
148                    \%params,
149          );          );
150    
151          die $SWISH::errstr unless $sh;          die $SWISH::errstr unless $sh;

Legend:
Removed from v.21  
changed lines
  Added in v.29

  ViewVC Help
Powered by ViewVC 1.1.26