/[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 10 - (show annotations)
Wed Aug 16 01:02:00 2006 UTC (17 years, 8 months ago) by dpavlin
File size: 2468 byte(s)
show time, simple query rewriter, status message tweaks
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use CGI::Simple;
6 use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
7 use Search::Estraier;
8 use YAML::Syck;
9 use Data::Dump qw/dump/;
10
11 my $q = new CGI::Simple;
12 print qq{Content-type: text/html\n\r\n\r};
13
14 my $config = LoadFile('config.yml');
15
16 #warn "config = ", dump($config);
17
18 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 my $node = new Search::Estraier::Node(%{ $config->{estraier} });
34
35 my $o = $q->param('index') || 0;
36 my $search = $q->param('q');
37 $search = join(" AND ", split(/\s+/, $search)) unless ($search =~ m/(?:AND|OR|\[|\])/);
38
39 my $on_page = 30;
40 my $skip = $o * $on_page;
41
42 my $cond = new Search::Estraier::Condition;
43 $cond->set_phrase( $search );
44 $cond->set_max( $on_page );
45 $cond->set_skip( $skip );
46
47 my $nres = $node->search($cond, ( $config->{estraier}->{depth} || 0 ) );
48
49 my $max = 0;
50
51 if (defined($nres)) {
52 $max = $nres->hits;
53 my $time = $nres->hint('TIME');
54 print qq{
55 <div id="status_update" style="display:none;">
56 Got <b>$max</b> results for <tt>$search</tt> in <em>$time s</em>
57 </div>
58 };
59
60 sub html_snippet {
61 my $text = shift || return;
62 my $out = '';
63 foreach my $s (split(/[\n\r]{2}/, $text)) {
64 $out .= ' ... ' if ($out);
65 my ($pre,$hit,$post) = split(/\n/,$s,3);
66 $hit =~ s/\t.*$//;
67 $out .=
68 $q->escapeHTML( $pre || '' ) . '<b>' .
69 $q->escapeHTML( $hit || '' ) . '</b>' .
70 $q->escapeHTML( $post || '');
71 }
72 return $out;
73 }
74
75
76 # for each document in results
77 for my $i ( 0 ... $nres->doc_num - 1 ) {
78
79 my $rdoc = $nres->get_doc($i);
80
81 print "<li>";
82
83 print "<h1>", $rdoc->attr('@title'),"</h1>\n";
84 print "<h2>", $rdoc->attr('source'),"</h2>\n";
85 print "<h3>", $rdoc->attr('@mdate'),"</h3>\n";
86 print "<p>", html_snippet( $rdoc->snippet ),"</p>\n";
87 print "[", $skip + $i, "] ";
88 print "<tt>", $rdoc->attr('@uri'),"</tt>";
89 print "</li>";
90 }
91 } else {
92 die "error: ", $node->status,"\n";
93 }
94
95
96 print qq{
97 </ul>
98 </div>
99
100 </div>
101
102 </html>
103 };
104
105 } else {
106
107 sub page_id {
108 my $page_id = time() . rand(99);
109 warn "page_id = $page_id\n";
110 return $page_id;
111 };
112
113 my $f = $q->path_info;
114 $f =~ s/\W+//g;
115 $f ||= 'search';
116 $f .= '.html';
117 open(my $s, $f) || die "$f: $!";
118 while(<$s>) {
119 no strict 'vars';
120 s/<%(.+?)%>/eval "$1"/ge;
121 print;
122 }
123 close($f);
124
125 }

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26