/[nn.old]/trunk/search/nn-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

Contents of /trunk/search/nn-swish.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 76 - (show annotations)
Wed Jun 26 08:55:39 2002 UTC (21 years, 10 months ago) by dpavlin
File MIME type: application/octet-stream
File size: 2035 byte(s)
rewrite query with +/- to and/and not

1 #!/usr/bin/perl -w
2
3 use strict;
4 use CGI qw/:standard -no_xhtml/;
5 use Text::Query;
6 use CGI::Carp qw(fatalsToBrowser);
7 use SWISH;
8 use Unicode::String qw(utf8 utf16);
9 require Unicode::Map8;
10
11 my $dir='/home/dpavlin/nn/swish';
12
13 my $hits=0;
14
15 print header(-charset=>'iso-8859-2'),start_html(-title=>'NN pretrazivanje',-lang=>'hr'),start_form;
16 print "Potra¾i zakone sa riječima: ",textfield('search');
17 print submit(-value=>'prika¾i');
18 print end_form,hr;
19
20 if (param('search')) {
21
22 my $s;
23 # re-write query from +/- to and/and not
24 foreach (split(/\s+/,param('search'))) {
25 if (m/^([+-])(\S+)/) {
26 $s.= ($s) ? "and " : "";
27 $s.="not " if ($1 eq "-");
28 $s.="$2 ";
29 } else {
30 $s .= "$_ ";
31 }
32 }
33 $s=~tr/ššžčꊩŽČĘ/¹š¾čę©Š®ČĘ/; # 1250 -> iso8859-2
34 $s=~tr/¹©šŠčČęĘ¾®/sSdDcCcCzZ/;
35
36 my $l2_map = Unicode::Map8->new("ISO-8859-2") || die;
37 my $us = Unicode::String->new();
38
39 my $sh = SWISH->connect('Fork',
40 prog => "$dir/swish-e",
41 indexes => "$dir/nn.index",
42 properties => [qw/god br nr/],
43 results => sub {
44 my ($sh,$hit) = @_;
45
46 $us->utf8($hit->swishtitle);
47
48 print "<a href=\"",$hit->swishdocpath,"\"><tt>NN",$hit->god,"/",$hit->br,"</a> ",$hit->nr," </tt>",$l2_map->to8($us->utf16),"</a> [",$hit->swishrank,"]<br>\n";
49
50 # print $_[1]->as_string,"<br>\n";
51 # my @fields = $hit->field_names;
52 # print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields;
53 },
54 );
55
56 die $SWISH::errstr unless $sh;
57
58 $hits = $sh->query("naslov_czs=($s)");
59
60 if ($hits > 0) {
61 print p,hr,"Našeno je $hits zakona... <small>($s)</small>";
62 } else {
63 print p,"Nije našen niti jedan zakon... <small>($s, ",$sh->errstr,")</small>";
64 }
65 } else {
66 print p('Kod pretra¾ivanja pretra¾ivač pronalazi sve zakone u kojima se pojavljuju <b>sve upisanje riječi</b>.',br,'Ako ispred riječi upi¹ete minus (-) neęe se prikazivati zakoni koji imaju takvu riječ. Npr. <tt>+kava +zakon -dopunama</tt>');
67 print p("Mo¾ete pročitati i <a href=\"http://www.rot13.org/~dpavlin/nn.html\">članak</a> o tome kako je ovaj pretra¾ivač napravljen i za¹to.");
68 }

Properties

Name Value
cvs2svn:cvs-rev 1.6
svn:executable *
svn:mime-type application/octet-stream

  ViewVC Help
Powered by ViewVC 1.1.26