/[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

Contents of /no_pager/index.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Tue Aug 15 15:43:31 2006 UTC (17 years, 8 months ago) by dpavlin
File size: 2100 byte(s)
import of first semi-working version of no pager

1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use CGI::Simple;
6 use CGI::Carp qw(fatalsToBrowser);
7 use Search::Estraier;
8
9 my $q = new CGI::Simple;
10 print qq{Content-type: text/html\n\r\n\r};
11
12 if ($q->path_info() eq '/snippet') {
13
14 print qq{
15 <HTML>
16 <HEAD>
17 <META CONTENT="text/html; charset=utf-8" HTTP-EQUIV="Content-Type">
18 <META CONTENT="no-cache" HTTP-EQUIV="Pragma">
19 <META CONTENT="-1" HTTP-EQUIV="Expires">
20 </HEAD>
21
22 <div>
23 <div class="post">
24 <ul>
25 };
26
27 my $node = new Search::Estraier::Node(
28 url => 'http://localhost:1978/node/cpan',
29 user => 'admin',
30 passwd => 'admin',
31 croak_on_error => 1,
32 );
33
34 my $o = $q->param('index') || 0;
35 my $search = $q->param('q');
36
37 my $on_page = 30;
38 my $skip = $o * $on_page;
39
40 my $cond = new Search::Estraier::Condition;
41 $cond->set_phrase( $search );
42 $cond->set_max( $on_page );
43 $cond->set_skip( $skip );
44
45 my $nres = $node->search($cond, 0);
46
47 my $max = 0;
48
49 if (defined($nres)) {
50 $max = $nres->hits;
51 print "Got ", $nres->hits, " results for $search\n";
52
53 sub html_snippet {
54 my $text = shift || return;
55 my $out = '';
56 foreach my $s (split(/[\n\r]{2}/, $text)) {
57 $out .= ' ... ' if ($out);
58 my ($pre,$hit,$post) = split(/\n/,$s,3);
59 $hit =~ s/\t.*$//;
60 $out .=
61 $q->escapeHTML( $pre || '' ) . '<b>' .
62 $q->escapeHTML( $hit || '' ) . '</b>' .
63 $q->escapeHTML( $post || '');
64 }
65 return $out;
66 }
67
68
69 # for each document in results
70 for my $i ( 0 ... $nres->doc_num - 1 ) {
71
72 my $rdoc = $nres->get_doc($i);
73
74 print "<ul>";
75
76 print "<h1>", $rdoc->attr('@title'),"</h1>\n";
77 print "<h2>", $rdoc->attr('source'),"</h2>\n";
78 print "", html_snippet( $rdoc->snippet ),"<br/>\n";
79 print "[", $skip + $i, "] ";
80 print "<tt>", $rdoc->attr('@uri'),"</tt>";
81 print "</ul>";
82 }
83 } else {
84 die "error: ", $node->status,"\n";
85 }
86
87
88 print qq{
89 </ul>
90 </div>
91
92 </div>
93
94 </html>
95 };
96
97 } else {
98
99 sub page_id {
100 my $page_id = time() . rand(99);
101 warn "page_id = $page_id\n";
102 return $page_id;
103 };
104
105 my $f = $q->path_info;
106 $f =~ s/\W+//g;
107 $f ||= 'search';
108 $f .= '.html';
109 open(my $s, $f) || die "$f: $!";
110 while(<$s>) {
111 s/<%(.*?)%>/eval "$1"/ge;
112 print;
113 }
114 close($f);
115
116 }

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26