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

Annotation of /no_pager/index.cgi

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26