7 use CGI::Carp qw/fatalsToBrowser/;
12 use Data::Dump qw/dump/;
15 my $entries_per_page = 30;
21 print qq|<pre># $name\n|, YAML::Dump( @_ ), qq|</pre>|;
25 my ($pager,$coderef) = @_;
28 my $after_current = 0;
30 if ( $pager->current_page <= $range_around + 2 ) {
31 @show_pages = ( $pager->first_page .. $pager->current_page );
32 $after_current = $range_around - $pager->current_page;
34 @show_pages = ( $pager->first_page, '', $pager->current_page - $range_around .. $pager->current_page );
37 if ( $pager->current_page + $range_around + 1 >= $pager->last_page ) {
38 push @show_pages, ( $pager->current_page + 1 .. $pager->last_page );
40 push @show_pages, ( $pager->current_page + 1 .. $pager->current_page + $after_current + $range_around, '', $pager->last_page );
43 warn "## show_pages = ",dump( @show_pages );
45 return join( ' ', map {
46 if ( $_ == $pager->current_page ) {
48 } elsif ( $_ eq '' ) {
56 my $path = $ENV{PATH_INFO} || 'ecas';
58 $dir =~ s{/[^/]+.cgi}{};
60 my $config = YAML::LoadFile( "$dir/$path/config.yml" );
62 my $database = (keys %{ $config->{databases} })[0];
63 die "$database not in $path" unless $path =~ m{\Q$database\E};
65 my $html_markup = "$dir/$path/html.pm";
67 if ( -e $html_markup ) {
69 $html_markup = $database . '::html';
74 my $estraier = YAML::LoadFile( "$dir/../var/estraier/$database.yaml" );
76 my $db = $config->{databases}->{$database};
78 my @attr = keys %{ $estraier->{attr} }; # FIXME replace with real gnerated lookup
82 -title => $db->{name},
83 -style => '../../style.css',
86 qq|<div id=description>|, $db->{description}, qq|</div>|,
93 textfield( -name => 'search' ),
95 textfield( -name => 'entries_per_page', -default => $entries_per_page ),
96 textfield( -name => 'current_page', -default => 1 ),
101 if ( my $search = param('search') ) {
103 print qq|<div id="results">|;
105 my $node = Search::Estraier::Node->new(
106 url => $config->{hyperestraier}->{masterurl} . '/node/' . $database,
110 param( 'entries_per_page', $entries_per_page ) unless param('entries_per_page'); # FIXME not needed?
112 my $cond = Search::Estraier::Condition->new;
113 $cond->set_phrase( $search );
114 $cond->set_skip( param('current_page') );
115 $cond->set_max( param('entries_per_page') );
116 my $nres = $node->search( $cond, 0 );
118 my $pager = Data::Page->new( $nres->hits, param('entries_per_page'), param('current_page') );
121 my $no_results = "No results for search '%s'";
122 printf qq|<div class="error">$no_results</div>|, $search;
125 my $results = "Got %d results for search '%s'";
126 printf qq|<div class="message">$results</div>|, $nres->hits, $search;
129 qq|<div class=pager>|,
133 param( 'current_page', $page );
134 my $url = self_url( -query => 1 );
135 qq|<a href="$url">$_</a>|;
141 my $start = $pager->first;
142 print qq|<ol start=$start>|;
144 foreach my $i ( 1 .. $nres->doc_num ) {
145 my $rdoc = $nres->get_doc( $i - 1 );
147 foreach my $attr ( @attr ) {
148 my $v = $rdoc->attr( $attr );
149 if ( defined $v && $html_markup && ! $html_markup_skip->{$attr} ) {
150 eval "\$v = $html_markup->$attr( \$v );";
152 warn "disable html markup for $attr: $@";
153 $html_markup_skip->{$attr} = $@;
156 next unless defined $v;
157 print qq|<div><label>$attr</label><span class=$attr>$v</span></div>\n|;
165 dump_yaml( 'pager', $pager );
169 dump_yaml( 'estraier', $estraier );
170 dump_yaml( 'db', $db );
171 dump_yaml( 'html_markup_skip', $html_markup_skip );