8 |
use Lingua::Spelling::Alternative; |
use Lingua::Spelling::Alternative; |
9 |
require Unicode::Map8; |
require Unicode::Map8; |
10 |
use GDBM_File; |
use GDBM_File; |
11 |
|
use lib '/data/swish/html'; |
12 |
|
use FormatResult; |
13 |
|
|
14 |
my $dir='/home/dpavlin/nn'; |
my $dir='/home/dpavlin/nn'; |
15 |
my $prog='/usr/bin/swish-e'; |
my $prog='/usr/bin/swish-e'; |
21 |
my %labels = (100=>' 100', 200=>' 200', 500=>' 500', 0=>'neograničeno'); |
my %labels = (100=>' 100', 200=>' 200', 500=>' 500', 0=>'neograničeno'); |
22 |
my %index = ('title'=>'naslovu', 'text'=>'tekstu'); |
my %index = ('title'=>'naslovu', 'text'=>'tekstu'); |
23 |
|
|
24 |
my %brs_labels; |
my %god_lables; |
25 |
|
|
26 |
my %brzakona; |
my %brzakona; |
27 |
tie %brzakona, 'GDBM_File', "$dir/swish/brzakona.gdbm", &GDBM_READER, 0640 || die "tie: $!"; |
tie %brzakona, 'GDBM_File', "$dir/swish/brzakona.gdbm", &GDBM_READER, 0640 || die "tie: $!"; |
28 |
foreach (sort keys %brzakona) { |
foreach (sort keys %brzakona) { |
29 |
$brs_labels{$_} = sprintf("%-8s (%d zakona)",$_,$brzakona{$_}); |
$god_lables{$_} = sprintf("%-8s (%d zakona)",$_,$brzakona{$_}); |
30 |
} |
} |
31 |
untie %brzakona; |
untie %brzakona; |
32 |
|
|
36 |
my $hr = new Lingua::Spelling::Alternative( DEBUG => 0 ); |
my $hr = new Lingua::Spelling::Alternative( DEBUG => 0 ); |
37 |
$hr->load_findaffix("$dir/prvih_50.txt"); |
$hr->load_findaffix("$dir/prvih_50.txt"); |
38 |
|
|
39 |
print header(-charset=>'iso-8859-2'),start_html(-title=>'NN pretrazivanje',-lang=>'hr'),start_form; |
print header(-charset=>'iso-8859-2'),start_html(-title=>'NN - Narodne Novine pretrazivanje',-lang=>'hr'),start_form(-name=>'search_form'); |
40 |
print "Potraži ",popup_menu(-name=>'max_hits',-values=>[ sort keys %labels ],-labels=>\%labels,-default=>$max_hits)," zakona sa riječima: ",textfield('search'); |
print "Potraži ",popup_menu(-name=>'max_hits',-values=>[ sort keys %labels ],-labels=>\%labels,-default=>$max_hits)," zakona sa riječima: ",textfield('search'); |
41 |
print " u ",popup_menu(-name=>'index',-values=>[ sort keys %index ],-labels=>\%index,-default=>'title')," zakona "; |
print " u ",popup_menu(-name=>'index',-values=>[ sort keys %index ],-labels=>\%index,-default=>'title')," zakona "; |
42 |
print submit(-value=>'prikaži'); |
print submit(-value=>'prikaži'); |
43 |
print br,checkbox(-name=>'br_limit', -checked=>0, -label=>"ograniči pretraživanje samo na godinu "),popup_menu(-name=>'br',-values=>[sort keys %brs_labels],-labels=>\%brs_labels); |
print br,checkbox(-name=>'god_limit', -checked=>0, -label=>"ograniči pretraživanje samo na godinu "),popup_menu(-name=>'god',-values=>[sort keys %god_lables],-labels=>\%god_lables,-onChange=>'this.form.god_limit.checked=true'); |
44 |
print end_form,hr; |
print end_form,hr; |
45 |
|
|
46 |
if (param('search')) { |
if (param('search')) { |
47 |
|
|
48 |
my $s; |
my $s; |
49 |
# re-write query from +/- to and/and not |
# re-write query from +/- to and/and not |
50 |
|
|
51 |
|
my @hl_words; |
52 |
|
|
53 |
foreach (split(/\s+/,param('search'))) { |
foreach (split(/\s+/,param('search'))) { |
54 |
if (m/^([+-])(\S+)/) { |
if (m/^([+-])(\S+)/) { |
55 |
$s.= ($s) ? "and " : ""; |
$s.= ($s) ? "and " : ""; |
56 |
$s.="not " if ($1 eq "-"); |
$s.="not " if ($1 eq "-"); |
57 |
$s.="(".join("* or ",$hr->alternatives($2)).") "; |
my @alt = $hr->alternatives($2); |
58 |
|
$s.="(".join("* or ",@alt).") "; |
59 |
|
push @hl_words, \@alt if ($1 ne "-"); |
60 |
} else { |
} else { |
61 |
$s .= "(".join("* or ",$hr->alternatives($_)).") "; |
my @alt = $hr->alternatives($_); |
62 |
|
$s .= "(".join("* or ",@alt).") "; |
63 |
|
push @hl_words, \@alt; |
64 |
} |
} |
65 |
} |
} |
66 |
$s=~tr/đčćĐČĆ/šđžčćŠĐŽČĆ/; # 1250 -> iso8859-2 |
$s=~tr/đčćĐČĆ/šđžčćŠĐŽČĆ/; # 1250 -> iso8859-2 |
83 |
|
|
84 |
$us->utf8($hit->swishtitle); |
$us->utf8($hit->swishtitle); |
85 |
|
|
86 |
print "<tt><a href=\"$url",$hit->swishdocpath,"\">NN",$hit->god,"/",$hit->br,"</a> ",$hit->nr," </tt>",$l2_map->to8($us->utf16)," [",$hit->swishrank,"]<br>\n"; |
my $naslov = $l2_map->to8($us->utf16); |
87 |
|
$naslov = FormatResult::highlite_words(\$naslov, \@hl_words); |
88 |
|
print "<tt><a href=\"$url",$hit->swishdocpath,"\">NN",$hit->god,"/",$hit->br,"</a> ",$hit->nr," </tt> $naslov [",$hit->swishrank,"]<br>\n"; |
89 |
# print $_[1]->as_string,"<br>\n"; |
# print $_[1]->as_string,"<br>\n"; |
90 |
# my @fields = $hit->field_names; |
# my @fields = $hit->field_names; |
91 |
# print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields; |
# print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields; |
96 |
die $SWISH::errstr unless $sh; |
die $SWISH::errstr unless $sh; |
97 |
|
|
98 |
$sw_q = "naslov_czs=($s)"; |
$sw_q = "naslov_czs=($s)"; |
99 |
if (param('br_limit')) { |
if (param('god_limit')) { |
100 |
$sw_q .= " and god=".int(param('br')) if (param('br')); |
$sw_q .= " and god=".int(param('god')) if (param('god')); |
101 |
} |
} |
102 |
|
|
103 |
} else { |
} else { |
112 |
my $path = $hit->swishdocpath; |
my $path = $hit->swishdocpath; |
113 |
if ($file2title{$path}) { |
if ($file2title{$path}) { |
114 |
my ($god,$br,$nr,undef,$naslov) = split(/ /,$file2title{$path},5); |
my ($god,$br,$nr,undef,$naslov) = split(/ /,$file2title{$path},5); |
115 |
|
$naslov = FormatResult::highlite_words(\$naslov, \@hl_words); |
116 |
print "<tt><a href=\"$url",$path,"\">NN$god/$br</a> $nr</tt> $naslov [",$hit->swishrank,"]<br>\n"; |
print "<tt><a href=\"$url",$path,"\">NN$god/$br</a> $nr</tt> $naslov [",$hit->swishrank,"]<br>\n"; |
117 |
|
|
118 |
} else { |
} else { |
126 |
die $SWISH::errstr unless $sh; |
die $SWISH::errstr unless $sh; |
127 |
|
|
128 |
$sw_q = $s; |
$sw_q = $s; |
129 |
if (param('br_limit')) { |
if (param('god_limit')) { |
130 |
$sw_q .= " and swishdocpath=".int(param('br')) if (param('br')); |
$sw_q .= " and swishdocpath=".int(param('god')) if (param('god')); |
131 |
} |
} |
132 |
|
|
133 |
} |
} |
138 |
|
|
139 |
if ($hits > 0) { |
if ($hits > 0) { |
140 |
print p,hr,"Prikazujem $hits zakona"; |
print p,hr,"Prikazujem $hits zakona"; |
141 |
print " iz broja ",param('br') if (param('br_limit')); |
print " iz godine ",param('god') if (param('god_limit')); |
142 |
print " (maks. ",param('max_hits') || $max_hits,")... <small>($s)</small>"; |
print " (maks. ",param('max_hits') || $max_hits,")... <small>($s)</small>"; |
143 |
} else { |
} else { |
144 |
print p,"Nije nađen niti jedan zakon... <small>($s, ",$sh->errstr,")</small>"; |
print p,"Nije nađen niti jedan zakon... <small>($s, ",$sh->errstr,")</small>"; |
145 |
} |
} |
146 |
} else { |
} else { |
147 |
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>'); |
my $dir=$0; |
148 |
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."),p("Novosti od rujna 2003.: pretraživanje po godinama i po punom tekstu zakona!"); |
$dir=~s,(^.*?)/[^/]+$,$1,g; |
149 |
|
open(HELP, "$dir/nn-help.html") || die "can't open '$dir/nn-help.html'"; |
150 |
|
while(<HELP>) { |
151 |
|
print; |
152 |
|
} |
153 |
|
close(HELP); |
154 |
} |
} |
155 |
|
|
156 |
untie %file2title; |
untie %file2title; |