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 + $after_current + $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 dump_yaml( 'show_pages', \@show_pages );
45 return '' unless $#show_pages;
47 my ( $prev, $next ) = ( '<<', '>>' );
50 $pager->previous_page ? $coderef->( $pager->previous_page, $prev ) : $prev
52 if ( $_ == $pager->current_page ) {
53 qq|<span class=current_page>$_</span>|;
54 } elsif ( $_ eq '' ) {
55 qq|<span class=skip>...</span>|;
60 , $pager->next_page ? $coderef->( $pager->next_page, $next ) : $next
65 my $path = $ENV{PATH_INFO} || 'ecas';
67 $dir =~ s{/[^/]+.cgi}{};
69 my $config = YAML::LoadFile( "$dir/$path/config.yml" );
71 my $database = (keys %{ $config->{databases} })[0];
72 die "$database not in $path" unless $path =~ m{\Q$database\E};
74 my $html_markup = "$dir/$path/html.pm";
76 if ( -e $html_markup ) {
78 $html_markup = $database . '::html';
83 my $estraier = YAML::LoadFile( "$dir/../var/estraier/$database.yaml" );
85 my $db = $config->{databases}->{$database};
87 my @attr = keys %{ $estraier->{attr} }; # FIXME replace with real gnerated lookup
91 -title => $db->{name},
92 -style => '../../style.css',
95 qq|<div id=description>|, $db->{description}, qq|</div>|,
96 start_form( -action => self_url( query => 0 ) ),
102 textfield( -name => 'search' ),
104 textfield( -name => 'entries_per_page', -default => $entries_per_page ),
105 textfield( -name => 'current_page', -default => 1 ),
110 if ( my $search = param('search') ) {
112 print qq|<div id="results">|;
114 my $node = Search::Estraier::Node->new(
115 url => $config->{hyperestraier}->{masterurl} . '/node/' . $database,
119 param( 'entries_per_page', $entries_per_page ) unless param('entries_per_page'); # FIXME not needed?
120 my $pager = Data::Page->new;
121 $pager->total_entries( param('current_page') * param('entries_per_page') );
122 $pager->$_( param($_) ) foreach ( qw/entries_per_page current_page/ );
124 dump_yaml( 'pager', $pager );
126 my $cond = Search::Estraier::Condition->new;
127 $cond->set_phrase( $search );
128 $cond->set_skip( $pager->skipped );
129 $cond->set_max( $pager->entries_per_page );
130 my $nres = $node->search( $cond, 0 );
131 $pager->total_entries( $nres->hits );
133 dump_yaml( 'cond', $cond );
136 my $no_results = "No results for search '%s'";
137 printf qq|<div class="error">$no_results</div>|, $search;
140 my $results = "Got %d results for search '%s'";
141 printf qq|<div class="message">$results</div>|, $nres->hits, $search;
144 qq|<div class=pager>|,
145 join(' ', show_pager( $pager,
147 my ($page,$label) = @_;
148 param( 'current_page', $page );
149 my $url = self_url( -query => 1 );
150 $label = $page unless defined $label;
151 qq|<a href="$url">$label</a>|;
157 my $start = $pager->first;
158 print qq|<ol start=$start>|;
160 foreach my $i ( 1 .. $nres->doc_num ) {
161 my $rdoc = $nres->get_doc( $i - 1 );
163 foreach my $attr ( @attr ) {
164 my $v = $rdoc->attr( $attr );
165 if ( defined $v && $html_markup && ! $html_markup_skip->{$attr} ) {
166 eval "\$v = $html_markup->$attr( \$v );";
168 warn "disable html markup for $attr: $@";
169 $html_markup_skip->{$attr} = $@;
172 next unless defined $v;
173 print qq|<div><label>$attr</label><span class=$attr>$v</span></div>\n|;
181 dump_yaml( 'pager', $pager );
185 dump_yaml( 'estraier', $estraier );
186 dump_yaml( 'db', $db );
187 dump_yaml( 'html_markup_skip', $html_markup_skip );