/[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 1137 by dpavlin, Tue Apr 21 23:17:23 2009 UTC revision 1138 by dpavlin, Wed Apr 22 10:14:56 2009 UTC
# Line 8  use CGI::Carp qw/fatalsToBrowser/; Line 8  use CGI::Carp qw/fatalsToBrowser/;
8  use File::Slurp;  use File::Slurp;
9  use YAML;  use YAML;
10  use Search::Estraier;  use Search::Estraier;
11    use Data::Page;
12    use Data::Dump qw/dump/;
13    
14    my $range_around = 5;
15    my $entries_per_page = 30;
16    
17  print header;  print header;
18    
# Line 16  sub dump_yaml { Line 21  sub dump_yaml {
21          print qq|<pre># $name\n|, YAML::Dump( @_ ), qq|</pre>|;          print qq|<pre># $name\n|, YAML::Dump( @_ ), qq|</pre>|;
22  }  }
23    
24    sub show_pages {
25            my ($pager,$coderef) = @_;
26    
27            my @show_pages;
28            my $after_current = 0;
29    
30            if ( $pager->current_page <= $range_around + 2 ) {
31                    @show_pages = ( $pager->first_page .. $pager->current_page );
32                    $after_current = $range_around - $pager->current_page;
33            } else {
34                    @show_pages = ( $pager->first_page, '', $pager->current_page - $range_around .. $pager->current_page );
35            }
36    
37            if ( $pager->current_page + $range_around + 1 >= $pager->last_page ) {
38                    push @show_pages, ( $pager->current_page + 1 .. $pager->last_page );
39            } else {
40                    push @show_pages, ( $pager->current_page + 1 .. $pager->current_page + $after_current + $range_around, '', $pager->last_page );
41            }
42    
43            warn "## show_pages = ",dump( @show_pages );
44    
45            return join( ' ', map {
46                    if ( $_ == $pager->current_page ) {
47                            qq|<b>$_</b>|;
48                    } elsif ( $_ eq '' ) {
49                            qq|...|;
50                    } else {
51                            $coderef->( $_ );
52                    }
53            } @show_pages );
54    }
55    
56  my $path = $ENV{PATH_INFO} || 'ecas';  my $path = $ENV{PATH_INFO} || 'ecas';
57  my $dir = $0;  my $dir = $0;
58  $dir =~ s{/[^/]+.cgi}{};  $dir =~ s{/[^/]+.cgi}{};
# Line 54  print Line 91  print
91  #                       -linebreak => 0,  #                       -linebreak => 0,
92                  ),                  ),
93                  textfield( -name => 'search' ),                  textfield( -name => 'search' ),
94                  submit                  submit,
95                    textfield( -name => 'entries_per_page', -default => $entries_per_page ),
96                    textfield( -name => 'current_page', -default => 1 ),
97  ;  ;
98    
99  print   end_form;  print   end_form;
# Line 68  if ( my $search = param('search') ) { Line 107  if ( my $search = param('search') ) {
107                  croak_on_error => 1,                  croak_on_error => 1,
108          );          );
109    
110            param( 'entries_per_page', $entries_per_page ) unless param('entries_per_page'); # FIXME not needed?
111    
112          my $cond = Search::Estraier::Condition->new;          my $cond = Search::Estraier::Condition->new;
113          $cond->set_phrase( $search );          $cond->set_phrase( $search );
114            $cond->set_skip( param('current_page') );
115            $cond->set_max( param('entries_per_page') );
116          my $nres = $node->search( $cond, 0 );          my $nres = $node->search( $cond, 0 );
117    
118            my $pager = Data::Page->new( $nres->hits, param('entries_per_page'), param('current_page') );
119    
120          if ( ! $nres ) {          if ( ! $nres ) {
121                  my $no_results = "No results for search '%s'";                  my $no_results = "No results for search '%s'";
122                  printf qq|<div class="error">$no_results</div>|, $search;                  printf qq|<div class="error">$no_results</div>|, $search;
123          } else {          } else {
124    
125                  my $results = "Got %d results for search '%s'";                  my $results = "Got %d results for search '%s'";
126                  printf qq|<div class="message">$results</div>|, $nres->hits, $search;                  printf qq|<div class="message">$results</div>|, $nres->hits, $search;
127    
128                  print qq|<ol>|;                  print
129                            qq|<div class=pager>|,
130                            show_pages( $pager,
131                                    sub {
132                                            my ($page) = @_;
133                                            param( 'current_page', $page );
134                                            my $url = self_url( -query => 1 );
135                                            qq|<a href="$url">$_</a>|;
136                                    }
137                            ),
138                            qq|</div>|
139                    ;
140    
141                    my $start = $pager->first;
142                    print qq|<ol start=$start>|;
143    
144                  foreach my $i ( 1 .. $nres->doc_num ) {                  foreach my $i ( 1 .. $nres->doc_num ) {
145                          my $rdoc = $nres->get_doc( $i - 1 );                          my $rdoc = $nres->get_doc( $i - 1 );
# Line 101  if ( my $search = param('search') ) { Line 161  if ( my $search = param('search') ) {
161                  print qq|</ol>|;                  print qq|</ol>|;
162          }          }
163          print qq|</div>|;          print qq|</div>|;
164    
165            dump_yaml( 'pager', $pager );
166    
167  }  }
168    
169  dump_yaml( 'estraier', $estraier );  dump_yaml( 'estraier', $estraier );

Legend:
Removed from v.1137  
changed lines
  Added in v.1138

  ViewVC Help
Powered by ViewVC 1.1.26