/[jquery]/no_pager/index.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 /no_pager/index.cgi

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

revision 18 by dpavlin, Wed Aug 16 23:37:51 2006 UTC revision 26 by dpavlin, Thu Aug 17 21:36:26 2006 UTC
# Line 25  my $v = { Line 25  my $v = {
25    
26  my $json;  my $json;
27    
28  #warn "config = ", dump($config);  sub debug {
29            my ($text,$var) = @_;
30            print "<pre>$text = ", dump($var), "</pre>";
31    }
32    
33    #debug('config', $config);
34    
35  sub json {  sub json {
36          return          return
# Line 34  sub json { Line 39  sub json {
39          '</textarea>';          '</textarea>';
40  }  }
41    
42    sub sort_order {
43            my $out;
44    
45            my $sort = $q->param('sort');
46    
47            $out .= '<select name="sort" id="sort">';
48    
49            foreach my $s (@{ $config->{estraier}->{order} }) {
50                    my ($text,$value) = %{$s};
51                    $out .= qq{<option value="$value"} .
52                            ( $sort eq $value ? ' selected' : '' ) .
53                            qq{>$text</option>};
54            }
55    
56            $out .= '</select>';
57    }
58    
59  sub get_results {  sub get_results {
60          my $p = {@_};          my $p = {@_};
61    
62          my ($search,$page) = ( $p->{search} || '', $p->{page} || 0);          my ($search,$page) = ( $p->{search} , $p->{page});
   
         warn "get_results( $search , $page )\n";  
63    
64          sub next_page {          sub next_page {
65                  return '<div id="next_page">' .                  return '<div id="next_page">' .
# Line 70  sub get_results { Line 90  sub get_results {
90          $cond->set_phrase( $search );          $cond->set_phrase( $search );
91          $cond->set_max( $on_page );          $cond->set_max( $on_page );
92          $cond->set_skip( $skip );          $cond->set_skip( $skip );
93            $cond->set_order( $p->{sort} ) if ($p->{sort});
94    
95          my $nres = $node->search($cond, ( $config->{estraier}->{depth} || 0 ) );          my $nres = $node->search($cond, ( $config->{estraier}->{depth} || 0 ) );
96    
97          my $out;          my $out;
98    
99          if (defined($nres)) {          if (defined($nres)) {
100    
101                  $v->{hits} = $nres->hits;                  $v->{hits} = $nres->hits;
102                  $v->{time} = $nres->hint('TIME');                  $v->{time} = $nres->hint('TIME');
103    
104                    if ($v->{hits} == 0) {
105                            $v->{status} = qq{<strong>No results for your search.</strong>};
106                            return next_page();
107                    } elsif ($nres->doc_num == 0) {
108                            $v->{status} = qq{<strong>Error getting results for page $page.</strong>};
109                            return next_page('<strong>No results found.</strong>');
110                    }
111    
112                  $v->{max_page} = int( ($nres->hits + $on_page - 1) / $on_page );                  $v->{max_page} = int( ($nres->hits + $on_page - 1) / $on_page );
113    
114                  $v->{status} = qq{                  $v->{status} = qq{
# Line 115  sub get_results { Line 146  sub get_results {
146                          return $text;                          return $text;
147                  }                  }
148    
149                    my @template;
150                    open(my $t, 'result.html')  || die "result.html: $!";
151                    while(<$t>) {
152                            push @template, $_;
153                    }
154                    close($t);
155    
156                  # for each document in results                  # for each document in results
157                  for my $i ( 0 ... $nres->doc_num - 1 ) {                  for my $i ( 0 ... $nres->doc_num - 1 ) {
158    
159                          my $rdoc = $nres->get_doc($i);                          my $rdoc = $nres->get_doc($i);
   
                         $out .= '<div class="item">' .  
                                 '<h1>' . $rdoc->attr('@title') . '</h1>' .  
                                 '<p>' . html_snippet( $rdoc->snippet ) . '</p>' .  
                                 '<h2>' . attr_regex( $rdoc, 'source' ) . '</h2>';  
160                          my $uri = attr_regex( $rdoc, '@uri' );                          my $uri = attr_regex( $rdoc, '@uri' );
161                          $out .=                          my $nr = $skip + $i + 1;
162                                  qq{<a href="$uri"><tt>$uri</tt></a> } .  
163                                  attr_regex( $rdoc, '@mdate' ) .                          map {
164                                  ' [' . ( $skip + $i + 1 ) . ']';                                  my $l = $_;
165                                    $l =~ s/<%(.+?)%>/eval "$1"/ge;
166                                    $out .= $l;
167                            } @template;
168    
169                  }                  }
170    
171          } else {          } else {
# Line 136  sub get_results { Line 173  sub get_results {
173          }          }
174    
175          if ($v->{page} == $v->{max_page}) {          if ($v->{page} == $v->{max_page}) {
176                  $out .= next_page('<strong>All results shown</strong>');                  $out .= next_page('<br/><strong>All results shown</strong>');
177          } else {          } else {
178                  $out .= next_page(                  $out .= next_page(
179                          '<strong>Loading results...</strong><br/>',                          '<br/><strong>Loading results...</strong><br/>',
180                          'If you are using the scroll bar, release the mouse to see more results.'                          'If you are using the scroll bar, release the mouse to see more results.'
181                  );                  );
182          }          }
# Line 151  sub get_results { Line 188  sub get_results {
188  if ($q->path_info() eq '/snippet') {  if ($q->path_info() eq '/snippet') {
189    
190          print get_results(          print get_results(
191                  search => $q->param('search'),                  search => $q->param('search') || '',
192                  page => $q->param('page'),                  page => $q->param('page') || 0,
193                    sort => $q->param('sort') || undef,
194          );          );
195    
196    
197  } else {  } else {
198    
199          my $get_results = get_results(          my $get_results = get_results(
200                  search => $q->param('search'),                  search => $q->param('search') || '',
201                  page => 1,                  page => 1,
202                    sort => $q->param('sort') || undef,
203          );          );
204    
205          my $f = $q->path_info;          my $f = $q->path_info;
# Line 172  if ($q->path_info() eq '/snippet') { Line 211  if ($q->path_info() eq '/snippet') {
211                  s/<%(.+?)%>/eval "$1"/ge;                  s/<%(.+?)%>/eval "$1"/ge;
212                  print;                  print;
213          }          }
214          close($f);          close($s);
215    
216  }  }

Legend:
Removed from v.18  
changed lines
  Added in v.26

  ViewVC Help
Powered by ViewVC 1.1.26