/[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 101 by dpavlin, Tue Feb 22 14:46:28 2005 UTC revision 106 by dpavlin, Mon Aug 4 15:28:56 2008 UTC
# Line 3  Line 3 
3  use strict;  use strict;
4  use CGI qw/:standard -no_xhtml/;  use CGI qw/:standard -no_xhtml/;
5  use CGI::Carp qw(fatalsToBrowser);  use CGI::Carp qw(fatalsToBrowser);
6  use SWISH;  use SWISH::API;
 use Unicode::String qw(utf8 utf16);  
7  use Lingua::Spelling::Alternative;  use Lingua::Spelling::Alternative;
8  require Unicode::Map8;  use Encode qw/from_to/;
9  use GDBM_File;  use GDBM_File;
10  use lib '/data/swish/html';  use lib '/data/swish/html';
11  use FormatResult;  use FormatResult;
12    
13  my $dir='/home/dpavlin/nn';  my $dir='/home/dpavlin/nn';
14  my $prog='/usr/bin/swish-e';  #my $prog='/usr/bin/swish-e';
15  my $url='http://www.nn.hr/clanci/sluzbeno/';  my $url='http://www.nn.hr/clanci/sluzbeno/';
16    
 my $hits=0;  
17  my $max_hits=100;  my $max_hits=100;
18    
19  my %labels = (100=>' 100', 200=>' 200', 500=>' 500', 0=>'neogranièeno');  my %labels = (100=>' 100', 200=>' 200', 500=>' 500', 0=>'neogranièeno');
# Line 66  if (param('search')) { Line 64  if (param('search')) {
64          $s=~tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/;  # 1250 -> iso8859-2          $s=~tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/;  # 1250 -> iso8859-2
65          $s=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/;          $s=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/;
66    
67          my $l2_map = Unicode::Map8->new("ISO-8859-2") || die;          my $swish_query;
         my $us = Unicode::String->new();  
   
         my $sw_q;  
         my $sh;  
68    
69          if (defined(param('max_hits'))) {          if (defined(param('max_hits'))) {
70                  $max_hits = param('max_hits');                  $max_hits = param('max_hits');
71          }          }
72    
73          if (param('index') eq 'title') {          my ( $index_path, $result_coderef );
   
                 $sh = SWISH->connect('Fork',  
                         prog     => $prog,  
                         indexes  => "$dir/swish/nn.index",  
                         properties  => [qw/god br nr/],  
                         results  => sub {  
                                 my ($sh,$hit) = @_;  
   
                                 $us->utf8($hit->swishtitle);  
74    
75                                  my $naslov = $l2_map->to8($us->utf16);          if (param('index') eq 'title') {
                                 $naslov = FormatResult::highlite_words(\$naslov, \@hl_words);  
                                 print "<tt><a href=\"$url",$hit->swishdocpath,"\">NN",$hit->god,"/",$hit->br,"</a> ",$hit->nr," </tt> $naslov [",$hit->swishrank,"]<br>\n";  
         #                       print $_[1]->as_string,"<br>\n";  
         #                       my @fields = $hit->field_names;  
         #                       print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields;  
                         },  
                         maxhits => $max_hits,  
                 );  
76    
77                  die $SWISH::errstr unless $sh;                  $result_coderef = sub {
78                            my $hit = shift || die;
79                            my $naslov = $hit->property('swishtitle');
80                            from_to($naslov, 'utf-8', 'iso-8859-2');
81                            $naslov = FormatResult::highlite_words(\$naslov, \@hl_words);
82                            print "<tt><a href=\"$url",$hit->property('swishdocpath'),"\">NN",$hit->property('god'),"/",$hit->property('br'),"</a> ",$hit->property('nr')," </tt> $naslov [",$hit->property('swishrank'),"]<br>\n";
83                    };
84    
85                  $sw_q = "naslov_czs=($s)";                  $index_path = "$dir/swish/nn.index";
86                    $swish_query = "naslov_czs=($s)";
87                  if (param('god_limit')) {                  if (param('god_limit')) {
88                          $sw_q .= " and god=".int(param('god')) if (param('god'));                          $swish_query .= " and god=".int(param('god')) if (param('god'));
89                  }                  }
90    
91          } else {          } else {
92                  # search in full text                  # search in full text
93    
94                  $sh = SWISH->connect('Fork',                  $result_coderef = sub {
95                          prog     => $prog,                          my $hit = shift || die;
                         indexes  => "$dir/swish/sluzbeno.index",  
                         results  => sub {  
                                 my ($sh,$hit) = @_;  
   
                                 my $path = $hit->swishdocpath;  
                                 if ($file2title{$path}) {  
                                         my ($god,$br,$nr,undef,$naslov) = split(/ /,$file2title{$path},5);  
                                         $naslov = FormatResult::highlite_words(\$naslov, \@hl_words);  
                                         print "<tt><a href=\"$url",$path,"\">NN$god/$br</a> $nr</tt> $naslov [",$hit->swishrank,"]<br>\n";  
   
                                 } else {  
                                         print "<!-- error! can't find $path -->\n";  
                                 }  
   
                         },  
                         maxhits => $max_hits,  
                 );  
96    
97                  die $SWISH::errstr unless $sh;                          my $path = $hit->property('swishdocpath');
98                            if ($file2title{$path}) {
99                                    my ($god,$br,$nr,undef,$naslov) = split(/ /,$file2title{$path},5);
100                                    $naslov = FormatResult::highlite_words(\$naslov, \@hl_words);
101                                    from_to($naslov, 'utf-8', 'iso-8859-2');
102                                    print "<tt><a href=\"$url",$path,"\">NN$god/$br</a> $nr</tt> $naslov [",$hit->property('swishrank'),"]<br>\n";
103    
104                  $sw_q = $s;                          } else {
105                                    print "<!-- error! can't find $path -->\n";
106                            }
107    
108                    };
109    
110                    $index_path = "$dir/swish/sluzbeno.index";
111                    $swish_query = $s;
112                  if (param('god_limit')) {                  if (param('god_limit')) {
113                          $sw_q .= " and swishdocpath=".int(param('god')) if (param('god'));                          $swish_query .= " and swishdocpath=".int(param('god')) if (param('god'));
114                  }                  }
115    
116          }          }
117    
118          print "<!-- swish query: $sw_q -->";          print "<!-- swish query: $swish_query -->";
119    
120            my $swish = SWISH::API->new( $index_path );
121            $swish->abort_last_error if $swish->Error;
122    
123          $hits = $sh->query($sw_q);          my $results = $swish->query($swish_query);
124    
125            my $hits = $results->hits;
126    
127          if ($hits > 0) {          if ($hits > 0) {
128                  print p,hr,"Prikazujem $hits zakona";                  my $i = 1;
129                    while ( my $hit = $results->next_result ) {
130                            $result_coderef->( $hit );
131                            last if $i++ == $max_hits;
132                    }
133    
134                    print p,hr,"Pronaðeno $hits zakona";
135                  print " iz godine ",param('god') if (param('god_limit'));                  print " iz godine ",param('god') if (param('god_limit'));
136                  print " (maks. $max_hits)... " if ($max_hits);                  print " (prikazano prvih $max_hits)... " if ($max_hits);
137                  print " <small>[$s]</small>";                  print " <small>[$s]</small>";
138          } else {          } else {
139                  print p,"Nije naðen niti jedan zakon... <small>[$s, ",$sh->errstr,"]</small>";                  print p,"Nije naðen niti jedan zakon... <small>[$s, ",$swish->error_string,"]</small>";
140          }          }
141  } else {  } else {
142          my $dir=$0;          my $dir=$0;

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

  ViewVC Help
Powered by ViewVC 1.1.26