/[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 15 by dpavlin, Wed Aug 16 21:34:37 2006 UTC revision 23 by dpavlin, Thu Aug 17 19:18: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 {
36            return
37            '<textarea id="json" style="display:none">' .
38            $q->escapeHTML( JSON::Syck::Dump( $v ) ) .
39            '</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 ($search, $page) = @_;          my $p = {@_};
61    
62          if (! $search) {          my ($search,$page) = ( $p->{search} , $p->{page});
63    
64            sub next_page {
65                    return '<div id="next_page">' .
66                            join("\n", @_) . json() . '</div>';
67            }
68    
69            if (! $search || $search =~ m/^\s*$/) {
70                  $v->{status} = 'Enter search query';                  $v->{status} = 'Enter search query';
71                  return;                  return next_page();
72          }          }
73    
74          if (! $page) {          if (! $page) {
75                  $v->{status} = 'Error: no page number?';                  $v->{status} = 'Error: no page number?';
76                  return;                  return next_page();
77          }          }
78    
79          $search = join(" AND ", split(/\s+/, $search)) unless ($search =~ m/(?:AND|OR|\[|\])/);          $search = join(" AND ", split(/\s+/, $search)) unless ($search =~ m/(?:AND|OR|\[|\])/);
80          $v->{search} = $search || '';          $v->{search} = $search;
81    
82          $v->{page} = $page;          $v->{page} = $page;
83    
# Line 54  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    
# Line 99  sub get_results { Line 136  sub get_results {
136                          return $text;                          return $text;
137                  }                  }
138    
139                    my @template;
140                    open(my $t, 'result.html')  || die "result.html: $!";
141                    while(<$t>) {
142                            push @template, $_;
143                    }
144                    close($t);
145    
146                  # for each document in results                  # for each document in results
147                  for my $i ( 0 ... $nres->doc_num - 1 ) {                  for my $i ( 0 ... $nres->doc_num - 1 ) {
148    
149                          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>';  
150                          my $uri = attr_regex( $rdoc, '@uri' );                          my $uri = attr_regex( $rdoc, '@uri' );
151                          $out .=                          my $nr = $skip + $i + 1;
152                                  qq{<a href="$uri"><tt>$uri</tt></a> } .  
153                                  attr_regex( $rdoc, '@mdate' ) .                          map {
154                                  ' [' . ( $skip + $i + 1 ) . ']';                                  my $l = $_;
155                                    $l =~ s/<%(.+?)%>/eval "$1"/ge;
156                                    $out .= $l;
157                            } @template;
158    
159                  }                  }
160    
161          } else {          } else {
162                  $out .= 'error: ' . $node->status;                  $out .= 'error: ' . $node->status;
163          }          }
164    
165          $json = '<textarea id="json" style="display:none">' .          if ($v->{page} == $v->{max_page}) {
166                  $q->escapeHTML( JSON::Syck::Dump( $v ) ) .                  $out .= next_page('<br/><strong>All results shown</strong>');
167                  '</textarea>';          } else {
168                    $out .= next_page(
169                            '<br/><strong>Loading results...</strong><br/>',
170                            'If you are using the scroll bar, release the mouse to see more results.'
171                    );
172            }
173    
174          return ($out,$json);          return $out;
175    
176  }  }
177    
178  if ($q->path_info() eq '/snippet') {  if ($q->path_info() eq '/snippet') {
179    
180          print join("\n<!-- json data -->",          print get_results(
181                  get_results(                  search => $q->param('search') || '',
182                          $q->param('search'),                  page => $q->param('page') || 0,
183                          $q->param('page'),                  sort => $q->param('sort') || undef,
                 )  
184          );          );
185    
186    
187  } else {  } else {
188    
189          my ($get_results, $json) = get_results( $q->param('search'), 1 );          my $get_results = get_results(
190                    search => $q->param('search') || '',
191                    page => 1,
192                    sort => $q->param('sort') || undef,
193            );
194    
195          my $f = $q->path_info;          my $f = $q->path_info;
196          $f =~ s/\W+//g;          $f =~ s/\W+//g;
# Line 150  if ($q->path_info() eq '/snippet') { Line 201  if ($q->path_info() eq '/snippet') {
201                  s/<%(.+?)%>/eval "$1"/ge;                  s/<%(.+?)%>/eval "$1"/ge;
202                  print;                  print;
203          }          }
204          close($f);          close($s);
205    
206  }  }

Legend:
Removed from v.15  
changed lines
  Added in v.23

  ViewVC Help
Powered by ViewVC 1.1.26