/[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 8 by dpavlin, Sun Mar 16 21:06:43 2003 UTC revision 29 by dpavlin, Mon Mar 24 09:04:57 2003 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    
 # output charset  
 my $CHARSET='ISO-8859-2';  
   
11  Text::Iconv->raise_error(0);     # Conversion errors raise exceptions  Text::Iconv->raise_error(0);     # Conversion errors raise exceptions
 my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET);  
   
12  my $config=XMLin(undef,  my $config=XMLin(undef,
13  #               keyattr => { label => "value" },  #               keyattr => { label => "value" },
14                  forcecontent => 0,                  forcecontent => 0,
15          );          );
16    
17  use Data::Dumper;  my $from_utf8 = Text::Iconv->new('UTF8', $config->{charset});
18  #print Dumper($config);  sub x {
19            return $from_utf8->convert($_[0]);
20    }
21    
22    # Escape <, >, & and ", and to produce valid XML
23    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
36    if ($config->{findaffix}) {
37            $spelling_alt = new Lingua::Spelling::Alternative;
38            $spelling_alt->load_findaffix(x($config->{findaffix}));
39    }
40  if ($config->{affix}) {  if ($config->{affix}) {
41          $spelling_alt = new Lingua::Spelling::Alternative;          $spelling_alt = new Lingua::Spelling::Alternative;
42          $spelling_alt->load_findaffix($config->{affix});          $spelling_alt->load_affix(x($config->{affix}));
43  }  }
44    
45  my $hits=0;  my $hits=0;
46  my $max_hits=$config->{max_hits};  my $max_hits=x($config->{max_hits});
47    
48  my %labels;  my %labels;
49  foreach (@{$config->{labels}->{label}}) {  foreach (@{$config->{labels}->{label}}) {
50          $labels{$_->{value}} = $from_utf8->convert($_->{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  print header(-charset=>$CHARSET),start_html(-title=>'Pretrazivanje',-lang=>'hr'),start_form;  if ($config->{charset}) {
62  print "Potra¾i ",popup_menu(-name=>'max_hits',-values=>[ sort keys %labels ],-labels=>\%labels,-default=>$max_hits)," dokumenata sa riječima: ",textfield('search');          print header(-charset=>x($config->{charset}));
63  print submit(-value=>'prika¾i');  } else {
64  print checkbox(-name=>'no_affix', -checked=>0, -label=>'ne koristi variranje oblika riječi');          print header;
65    }
66    print start_html(-title=>x($config->{title})),start_form;
67    print x($config->{text}->{search});
68    print popup_menu(-name=>'max_hits',-values=>[ sort keys %labels ],-labels=>\%labels,-default=>$max_hits);
69    print x($config->{text}->{documents});
70    print textfield('search');
71    print submit(-value=> x($config->{text}->{submit}));
72    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 83  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}));
125            $params{properties} = \@properties if (@properties);
126    
127          my $sh = SWISH->connect('Fork',          my $sh = SWISH->connect('Fork',
128                  prog     => $config->{prog},                  prog     => x($config->{prog}),
129                  indexes  => $config->{index},                  indexes  => x($config->{index}),
 #               properties  => [qw/god br nr/],  
130                  results  => sub {                  results  => sub {
131                          my ($sh,$hit) = @_;                          my ($sh,$hit) = @_;
132    
133                          print "<a href=\"",$hit->swishdocpath,"\">",$hit->swishtitle,"</a> [",$hit->swishrank,"]<br>\n";                          my $hit_fmt = x($config->{hit}) ||
134                                    "<a href=\"%s\">%s</a> [%s]<br>\n";
135    
136                            if ($config->{url}) {
137                                    printf ($hit_fmt ,"http://".virtual_host().x($config->{url}).$hit->swishdocpath,e($hit->swishtitle) || 'untitled',$hit->swishrank);
138                            } else {
139                                    printf ($hit_fmt ,$hit->swishdocpath,e($hit->swishtitle) || 'untitled',$hit->swishrank, map($hit->$_, @properties) );
140    
141                            }
142    
143  #                       print $_[1]->as_string,"<br>\n";  #                       print $_[1]->as_string,"<br>\n";
144  #                       my @fields = $hit->field_names;  #                       my @fields = $hit->field_names;
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;
# Line 105  if (param('search')) { Line 154  if (param('search')) {
154          $hits = $sh->query($s);          $hits = $sh->query($s);
155    
156          if ($hits > 0) {          if ($hits > 0) {
157                  print p,hr,"Prikazujem $hits dokumenata (maks. ",param('max_hits') || $max_hits,")... <small>($s)</small>";                  print p,hr;
158                    printf (x($config->{text}->{hits}),$hits,param('max_hits') || $max_hits,$s);
159          } else {          } else {
160                  print p,"Nije našen niti jedan dokument... <small>($s, ",$sh->errstr,")</small>";                  print p;
161                    printf (x($config->{text}->{no_hits}),$s,$sh->errstr);
162          }          }
163  } else {  } else {
164          print p('Kod pretra¾ivanja pretra¾ivač pronalazi sve dokumente u kojima se pojavljuju <b>sve upisanje riječi</b>.',br,'Ako ispred riječi upi¹ete minus (-) neęe se prikazivati dokumenti koji imaju takvu riječ. Npr. <tt>+mreza -novak</tt>');          print p(x($config->{text}->{footer}));
165  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26