/[webpac2]/trunk/vhost/webpac2.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/vhost/webpac2.cgi

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

revision 1143 by dpavlin, Thu Apr 23 10:59:01 2009 UTC revision 1149 by dpavlin, Fri Apr 24 16:58:09 2009 UTC
# Line 7  use CGI qw/:standard/; Line 7  use CGI qw/:standard/;
7  use CGI::Carp qw/fatalsToBrowser/;  use CGI::Carp qw/fatalsToBrowser/;
8  use File::Slurp;  use File::Slurp;
9  use YAML;  use YAML;
 use Search::Estraier;  
10  use Data::Page;  use Data::Page;
11  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
12    use SWISH::API;
13    use JSON;
14    
15  my $range_around = 5;  my $range_around = 5;
16  my $entries_per_page = 30;  my $entries_per_page = 30;
# Line 143  if ( my $search = param('search') ) { Line 144  if ( my $search = param('search') ) {
144    
145          print qq|<div id="results">|;          print qq|<div id="results">|;
146    
147          my $node = Search::Estraier::Node->new(          my $swish = SWISH::API->new( "$dir/../var/swish/$database" );
148                  url => $config->{hyperestraier}->{masterurl} . '/node/' . $database,          $swish->abort_last_error if $swish->Error;
                 croak_on_error => 1,  
         );  
149    
150          param( 'entries_per_page', $entries_per_page ) unless param('entries_per_page'); # FIXME not needed?          param( 'entries_per_page', $entries_per_page ) unless param('entries_per_page'); # FIXME not needed?
151          my $pager = Data::Page->new;          my $pager = Data::Page->new;
# Line 155  if ( my $search = param('search') ) { Line 154  if ( my $search = param('search') ) {
154    
155          dump_yaml( 'pager', $pager );          dump_yaml( 'pager', $pager );
156    
157          my $cond = Search::Estraier::Condition->new( debug => $debug );          my @search = ( "xml=$search" );
         $cond->set_phrase( $search );  
         $cond->set_skip( $pager->skipped );  
         $cond->set_max(  $pager->entries_per_page );  
158    
159          if ( my $op = param('attr_operator') ) {  #       if ( my $op = param('attr_operator') ) {
160                  $cond->add_attr( param('attr') . " $op " . param('search') );  #               $cond->add_attr( param('attr') . " $op " . param('search') );
161          }  #       }
162    
163          foreach my $i ( param('only_input') ) {          my @only_input = param('only_input');
                 $cond->add_attr( '@uri STRBW file:///search/' . $database . '/' . $i );  
         }  
164    
165            push @search, '(' . join(') or (', @only_input) . ')' if @only_input;
166    
167          my $nres = $node->search( $cond, 0 );          my $q = '(' . join(') and (', @search) . ')';
168          $pager->total_entries( $nres->hits );          warn "# query: $q\n";
169            my $swish_results = $swish->query( $q );
170            $swish->abort_last_error if $swish->Error;
171    
172          dump_yaml( 'cond', $cond );          dump_yaml( 'swish_results', $swish_results );
         dump_yaml( 'nres', $nres );  
173    
174          if ( ! $nres ) {          $pager->total_entries( $swish_results->hits );
175    
176            if ( ! $pager->total_entries ) {
177                  my $no_results = "No results for search '%s'";                  my $no_results = "No results for search '%s'";
178                  printf qq|<div class="error">$no_results</div>\n\n|, $search;                  printf qq|<div class="error">$no_results</div>\n\n|, $search;
179          } else {          } else {
180    
181                  my $results = "%d results for search '%s' showing results %d - %d on page %d";                  my $results = "%d results for search '%s' showing results %d - %d on page %d";
182                  printf qq|<div class="message">$results</div>\n\n|, $nres->hits, $search, $pager->first, $pager->last, $pager->current_page;                  printf qq|<div class="message">$results</div>\n\n|, $pager->total_entries, $search, $pager->first, $pager->last, $pager->current_page;
183    
184                  my $pager_html = join("\n", show_pager( $pager ));                  my $pager_html = join("\n", show_pager( $pager ));
185    
# Line 190  if ( my $search = param('search') ) { Line 188  if ( my $search = param('search') ) {
188                  my $start = $pager->first;                  my $start = $pager->first;
189                  print qq|<ol start=$start>\n|;                  print qq|<ol start=$start>\n|;
190    
191                  foreach my $i ( 1 .. $nres->doc_num ) {                  while ( my $result = $swish_results->next_result ) {
192                          my $rdoc = $nres->get_doc( $i - 1 );                          my $data = from_json $result->property('data');
193    
194                          print qq|<li>|;                          print qq|<li>|;
195                          foreach my $attr ( @attr ) {                          foreach my $attr ( @attr ) {
196                                  my $v = $rdoc->attr( $attr );                                  next unless defined $data->{$attr};
197                                  if ( defined $v && $html_markup && ! $html_markup_skip->{$attr} ) {                                  my $v = $data->{$attr};
198                                    if ( $html_markup && ! $html_markup_skip->{$attr} ) {
199                                          eval "\$v = $html_markup->$attr( \$v );";                                          eval "\$v = $html_markup->$attr( \$v );";
200                                          if ( $@ ) {                                          if ( $@ ) {
201                                                  warn "disable html markup for $attr: $@";                                                  warn "disable html markup for $attr: $@";
202                                                  $html_markup_skip->{$attr} = $@;                                                  $html_markup_skip->{$attr} = $@;
203                                          }                                          }
204                                  }                                  }
                                 next unless defined $v;  
205                                  print qq|<div><label>$attr</label><span class=$attr>$v</span></div>\n|;                                  print qq|<div><label>$attr</label><span class=$attr>$v</span></div>\n|;
206                          }                          }
207                          print qq|</li>\n|;                          print qq|</li>\n|;
# Line 217  if ( my $search = param('search') ) { Line 216  if ( my $search = param('search') ) {
216    
217  }  }
218    
 dump_yaml( 'estraier', $estraier );  
219  dump_yaml( 'db', $db );  dump_yaml( 'db', $db );
220  dump_yaml( 'html_markup_skip', $html_markup_skip );  dump_yaml( 'html_markup_skip', $html_markup_skip );
221    

Legend:
Removed from v.1143  
changed lines
  Added in v.1149

  ViewVC Help
Powered by ViewVC 1.1.26