/[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 83 - (show annotations)
Wed Sep 18 10:03:18 2002 UTC (21 years, 7 months ago) by dpavlin
File MIME type: application/octet-stream
File size: 2459 byte(s)
Text::Query is not used!

1 #!/usr/bin/perl -w
2
3 use strict;
4 use CGI qw/:standard -no_xhtml/;
5 use CGI::Carp qw(fatalsToBrowser);
6 use SWISH;
7 use Unicode::String qw(utf8 utf16);
8 require Unicode::Map8;
9
10 my $dir='/home/dpavlin/nn/swish';
11
12 my $hits=0;
13 my $max_hits=100;
14
15 my %labels = (100=>' 100', 200=>' 200', 500=>' 500', 0=>'neograničeno');
16
17 print header(-charset=>'iso-8859-2'),start_html(-title=>'NN pretrazivanje',-lang=>'hr'),start_form;
18 print "Potraži ",popup_menu(-name=>'max_hits',-values=>[ sort keys %labels ],-labels=>\%labels,-default=>$max_hits)," zakona sa riječima: ",textfield('search');
19 print submit(-value=>'prikaži');
20 print end_form,hr;
21
22 if (param('search')) {
23
24 my $s;
25 # re-write query from +/- to and/and not
26 foreach (split(/\s+/,param('search'))) {
27 if (m/^([+-])(\S+)/) {
28 $s.= ($s) ? "and " : "";
29 $s.="not " if ($1 eq "-");
30 $s.="$2* ";
31 } else {
32 $s .= "$_* ";
33 }
34 }
35 $s=~tr/šđžčćŠĐŽČĆ/šđžčćŠĐŽČĆ/; # 1250 -> iso8859-2
36 $s=~tr/šŠđĐčČćĆžŽ/sSdDcCcCzZ/;
37
38 my $l2_map = Unicode::Map8->new("ISO-8859-2") || die;
39 my $us = Unicode::String->new();
40
41 my $sh = SWISH->connect('Fork',
42 prog => "$dir/swish-e",
43 indexes => "$dir/nn.index",
44 properties => [qw/god br nr/],
45 results => sub {
46 my ($sh,$hit) = @_;
47
48 $us->utf8($hit->swishtitle);
49
50 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";
51
52 # print $_[1]->as_string,"<br>\n";
53 # my @fields = $hit->field_names;
54 # print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields;
55 },
56 maxhits => param('max_hits') || $max_hits,
57 );
58
59 die $SWISH::errstr unless $sh;
60
61 $hits = $sh->query("naslov_czs=($s)");
62
63 if ($hits > 0) {
64 print p,hr,"Prikazujem $hits zakona (maks. ",param('max_hits') || $max_hits,")... <small>($s)</small>";
65 } else {
66 print p,"Nije nađen niti jedan zakon... <small>($s, ",$sh->errstr,")</small>";
67 }
68 } else {
69 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>');
70 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."),p("Ovo je <i>nova i brža verzija pretraživača</i> o kojoj <a href=\"http://www.rot13.org/~dpavlin/nn.html#buducnost\">više možete saznati</a> iz članka.");
71 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26