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 |
|
my $from_utf8 = Text::Iconv->new('UTF8', $config->{charset}); |
18 |
|
sub x { |
19 |
|
return $from_utf8->convert($_[0]); |
20 |
|
} |
21 |
|
|
22 |
use Data::Dumper; |
use Data::Dumper; |
23 |
#print Dumper($config); |
#print Dumper($config); |
24 |
|
|
25 |
my $spelling_alt; |
my $spelling_alt; |
26 |
# FIX: doesn't work very well |
# FIX: doesn't work very well |
27 |
|
if ($config->{findaffix}) { |
28 |
|
$spelling_alt = new Lingua::Spelling::Alternative; |
29 |
|
$spelling_alt->load_findaffix(x($config->{findaffix})); |
30 |
|
} |
31 |
if ($config->{affix}) { |
if ($config->{affix}) { |
32 |
$spelling_alt = new Lingua::Spelling::Alternative; |
$spelling_alt = new Lingua::Spelling::Alternative; |
33 |
$spelling_alt->load_findaffix($config->{affix}); |
$spelling_alt->load_affix(x($config->{affix})); |
34 |
} |
} |
35 |
|
|
36 |
my $hits=0; |
my $hits=0; |
37 |
my $max_hits=$config->{max_hits}; |
my $max_hits=x($config->{max_hits}); |
38 |
|
|
39 |
my %labels; |
my %labels; |
40 |
foreach (@{$config->{labels}->{label}}) { |
foreach (@{$config->{labels}->{label}}) { |
41 |
$labels{$_->{value}} = $from_utf8->convert($_->{content}); |
$labels{$_->{value}} = x($_->{content}); |
42 |
|
} |
43 |
|
|
44 |
|
my $path = param('path'); # limit to this path |
45 |
|
my %path_label; |
46 |
|
my @path_name; |
47 |
|
foreach (@{$config->{paths}->{path}}) { |
48 |
|
push @path_name,x($_->{limit}); |
49 |
|
$path_label{$_->{limit}} = x($_->{content}); |
50 |
} |
} |
51 |
|
|
52 |
print header(-charset=>$CHARSET),start_html(-title=>'Pretrazivanje',-lang=>'hr'),start_form; |
if ($config->{charset}) { |
53 |
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})); |
54 |
print submit(-value=>'prika¾i'); |
} else { |
55 |
print checkbox(-name=>'no_affix', -checked=>0, -label=>'ne koristi variranje oblika riječi'); |
print header; |
56 |
|
} |
57 |
|
print start_html(-title=>x($config->{title})),start_form; |
58 |
|
print x($config->{text}->{search}); |
59 |
|
print popup_menu(-name=>'max_hits',-values=>[ sort keys %labels ],-labels=>\%labels,-default=>$max_hits); |
60 |
|
print x($config->{text}->{documents}); |
61 |
|
print textfield('search'); |
62 |
|
print submit(-value=> x($config->{text}->{submit})); |
63 |
|
print checkbox(-name=>'no_affix', -checked=>0, -label=>x($config->{text}->{no_spell})) if ($spelling_alt); |
64 |
|
if (@path_name) { |
65 |
|
print br,x($config->{text}->{limit}); |
66 |
|
print popup_menu(-name=>'path',-values=>\@path_name,-labels=>\%path_label,-default=>$path); |
67 |
|
} |
68 |
print end_form,hr; |
print end_form,hr; |
69 |
|
|
70 |
if (param('search')) { |
if (param('search')) { |
107 |
$s=~tr/¹©šŠčČęĘ¾®/sSdDcCcCzZ/; |
$s=~tr/¹©šŠčČęĘ¾®/sSdDcCcCzZ/; |
108 |
$s=~s/\*\*+/*/g; |
$s=~s/\*\*+/*/g; |
109 |
|
|
110 |
|
# limit to some path |
111 |
|
$s = "swishdocpath=($path) and $s" if ($path); |
112 |
|
|
113 |
|
my %params; # optional parametars for swish |
114 |
|
|
115 |
|
my @properties = split(/\s+/,x($config->{properties})); |
116 |
|
$params{properties} = \@properties if (@properties); |
117 |
|
|
118 |
my $sh = SWISH->connect('Fork', |
my $sh = SWISH->connect('Fork', |
119 |
prog => $config->{prog}, |
prog => x($config->{prog}), |
120 |
indexes => $config->{index}, |
indexes => x($config->{index}), |
|
# properties => [qw/god br nr/], |
|
121 |
results => sub { |
results => sub { |
122 |
my ($sh,$hit) = @_; |
my ($sh,$hit) = @_; |
123 |
|
|
124 |
print "<a href=\"",$hit->swishdocpath,"\">",$hit->swishtitle,"</a> [",$hit->swishrank,"]<br>\n"; |
my $hit_fmt = x($config->{hit}) || |
125 |
|
"<a href=\"%s\">%s</a> [%s]<br>\n"; |
126 |
|
|
127 |
|
if ($config->{url}) { |
128 |
|
printf ($hit_fmt ,"http://".virtual_host().x($config->{url}).$hit->swishdocpath,$hit->swishtitle || 'untitled',$hit->swishrank); |
129 |
|
} else { |
130 |
|
printf ($hit_fmt ,$hit->swishdocpath,$hit->swishtitle || 'untitled',$hit->swishrank, map($hit->$_, @properties) ); |
131 |
|
|
132 |
|
} |
133 |
|
|
134 |
# print $_[1]->as_string,"<br>\n"; |
# print $_[1]->as_string,"<br>\n"; |
135 |
# my @fields = $hit->field_names; |
# my @fields = $hit->field_names; |
136 |
# print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields; |
# print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields; |
137 |
}, |
}, |
138 |
maxhits => param('max_hits') || $max_hits, |
maxhits => param('max_hits') || $max_hits, |
139 |
|
\%params, |
140 |
); |
); |
141 |
|
|
142 |
die $SWISH::errstr unless $sh; |
die $SWISH::errstr unless $sh; |
145 |
$hits = $sh->query($s); |
$hits = $sh->query($s); |
146 |
|
|
147 |
if ($hits > 0) { |
if ($hits > 0) { |
148 |
print p,hr,"Prikazujem $hits dokumenata (maks. ",param('max_hits') || $max_hits,")... <small>($s)</small>"; |
print p,hr; |
149 |
|
printf (x($config->{text}->{hits}),$hits,param('max_hits') || $max_hits,$s); |
150 |
} else { |
} else { |
151 |
print p,"Nije našen niti jedan dokument... <small>($s, ",$sh->errstr,")</small>"; |
print p; |
152 |
|
printf (x($config->{text}->{no_hits}),$s,$sh->errstr); |
153 |
} |
} |
154 |
} else { |
} else { |
155 |
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})); |
156 |
} |
} |