/[webpac2]/trunk/vhost/webpac2.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 /trunk/vhost/webpac2.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1132 - (show annotations)
Tue Apr 21 21:06:31 2009 UTC (15 years ago) by dpavlin
File size: 1841 byte(s)
 r1770@llin:  dpavlin | 2009-04-21 23:06:28 +0200
 skeleton of web-based database searcher using simple CGI

1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use CGI qw/:standard/;
7 use CGI::Carp qw/fatalsToBrowser/;
8 use File::Slurp;
9 use YAML;
10 use Search::Estraier;
11
12 print header;
13
14 sub dump_yaml {
15 print qq|<pre>|, YAML::Dump( @_ ), qq|</pre>|;
16 }
17
18 my $path = $ENV{PATH_INFO};
19 my $dir = $0;
20 $dir =~ s{/[^/]+.cgi}{};
21
22 my $config = YAML::LoadFile( "$dir/$path/config.yml" );
23
24 my $database = (keys %{ $config->{databases} })[0];
25 die "$database not in $path" unless $path =~ m{\Q$database\E};
26
27 my $estraier = YAML::LoadFile( "$dir/../var/estraier/$database.yaml" );
28
29 my $db = $config->{databases}->{$database};
30
31 my @attr = keys %{ $estraier->{attr} }; # FIXME replace with real gnerated lookup
32
33 print
34 start_html(
35 -title => $db->{name},
36 -style => '../../style.css',
37 ),
38 h1( $db->{name} ),
39 qq|<div id=description>|, $db->{description}, qq|</div>|,
40 start_form,
41 radio_group(
42 -name => 'attr',
43 -values => [ 'issn', 'naslov' ],
44 # -linebreak => 0,
45 ),
46 textfield( -name => 'search' ),
47 submit
48 ;
49
50 print end_form;
51
52 if ( my $search = param('search') ) {
53
54 print qq|<div id="results">search: $search|;
55
56 my $node = Search::Estraier::Node->new(
57 url => $config->{hyperestraier}->{masterurl} . '/node/' . $database,
58 croak_on_error => 1,
59 );
60
61 my $cond = Search::Estraier::Condition->new;
62 $cond->set_phrase( $search );
63 my $nres = $node->search( $cond, 0 );
64
65 if ( ! $nres ) {
66 my $no_results = "No results for search '%s'";
67 printf qq|<div class="error">$no_results</a>|, $search;
68 } else {
69 print qq|<ul>|;
70 foreach my $i ( 1 .. $nres->doc_num ) {
71 my $rdoc = $nres->get_doc( $i - 1 );
72 print qq|<li>|;
73 print qq|<div><label>$_</label><span class=$_>|, $rdoc->attr( $_ ), qq|</span></div>|
74 foreach @attr;
75 print qq|</li>\n|;
76 }
77 print qq|</ul>|;
78 }
79 print qq|</div>|;
80 }
81
82 dump_yaml( $estraier );
83 dump_yaml( $db );
84
85 print end_html;

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26