/[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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 95 by dpavlin, Mon Sep 29 09:39:33 2003 UTC revision 101 by dpavlin, Tue Feb 22 14:46:28 2005 UTC
# Line 8  use Unicode::String qw(utf8 utf16); Line 8  use Unicode::String qw(utf8 utf16);
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';
# Line 34  tie %file2title, 'GDBM_File', "$dir/swis Line 36  tie %file2title, 'GDBM_File', "$dir/swis
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=>'Narodne Novine pretrazivanje',-lang=>'hr'),start_form(-name=>'search_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');
# Line 45  if (param('search')) { Line 47  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
# Line 63  if (param('search')) { Line 72  if (param('search')) {
72          my $sw_q;          my $sw_q;
73          my $sh;          my $sh;
74    
75            if (defined(param('max_hits'))) {
76                    $max_hits = param('max_hits');
77            }
78    
79          if (param('index') eq 'title') {          if (param('index') eq 'title') {
80    
81                  $sh = SWISH->connect('Fork',                  $sh = SWISH->connect('Fork',
# Line 74  if (param('search')) { Line 87  if (param('search')) {
87    
88                                  $us->utf8($hit->swishtitle);                                  $us->utf8($hit->swishtitle);
89    
90                                  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);
91                                    $naslov = FormatResult::highlite_words(\$naslov, \@hl_words);
92                                    print "<tt><a href=\"$url",$hit->swishdocpath,"\">NN",$hit->god,"/",$hit->br,"</a> ",$hit->nr," </tt> $naslov [",$hit->swishrank,"]<br>\n";
93          #                       print $_[1]->as_string,"<br>\n";          #                       print $_[1]->as_string,"<br>\n";
94          #                       my @fields = $hit->field_names;          #                       my @fields = $hit->field_names;
95          #                       print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields;          #                       print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields;
96                          },                          },
97                          maxhits => param('max_hits') || $max_hits,                          maxhits => $max_hits,
98                  );                  );
99    
100                  die $SWISH::errstr unless $sh;                  die $SWISH::errstr unless $sh;
# Line 102  if (param('search')) { Line 116  if (param('search')) {
116                                  my $path = $hit->swishdocpath;                                  my $path = $hit->swishdocpath;
117                                  if ($file2title{$path}) {                                  if ($file2title{$path}) {
118                                          my ($god,$br,$nr,undef,$naslov) = split(/ /,$file2title{$path},5);                                          my ($god,$br,$nr,undef,$naslov) = split(/ /,$file2title{$path},5);
119                                            $naslov = FormatResult::highlite_words(\$naslov, \@hl_words);
120                                          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";
121    
122                                  } else {                                  } else {
# Line 109  if (param('search')) { Line 124  if (param('search')) {
124                                  }                                  }
125    
126                          },                          },
127                          maxhits => param('max_hits') || $max_hits,                          maxhits => $max_hits,
128                  );                  );
129    
130                  die $SWISH::errstr unless $sh;                  die $SWISH::errstr unless $sh;
# Line 128  if (param('search')) { Line 143  if (param('search')) {
143          if ($hits > 0) {          if ($hits > 0) {
144                  print p,hr,"Prikazujem $hits zakona";                  print p,hr,"Prikazujem $hits zakona";
145                  print " iz godine ",param('god') if (param('god_limit'));                  print " iz godine ",param('god') if (param('god_limit'));
146                  print " (maks. ",param('max_hits') || $max_hits,")... <small>($s)</small>";                  print " (maks. $max_hits)... " if ($max_hits);
147                    print " <small>[$s]</small>";
148          } else {          } else {
149                  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>";
150          }          }
151  } else {  } else {
152          my $dir=$0;          my $dir=$0;

Legend:
Removed from v.95  
changed lines
  Added in v.101

  ViewVC Help
Powered by ViewVC 1.1.26