7 use CGI::Carp qw/fatalsToBrowser/;
12 use Data::Dump qw/dump/;
15 my $entries_per_page = 30;
16 my $debug = param('debug');
24 print qq|<pre># $name\n|, YAML::Dump( @_ ), qq|</pre>| if $debug;
31 my $after_current = 0;
33 if ( $pager->current_page <= $range_around + 2 ) {
34 @show_pages = ( $pager->first_page .. $pager->current_page );
35 $after_current = $range_around - $pager->current_page;
37 @show_pages = ( $pager->first_page, '', $pager->current_page - $range_around .. $pager->current_page );
40 if ( $pager->current_page + $after_current + $range_around + 1 >= $pager->last_page ) {
41 push @show_pages, ( $pager->current_page + 1 .. $pager->last_page );
43 push @show_pages, ( $pager->current_page + 1 .. $pager->current_page + $after_current + $range_around, '', $pager->last_page );
46 # dump_yaml( 'show_pages', \@show_pages );
48 return '' unless $#show_pages;
50 my ( $prev, $next ) = ( '<<', '>>' );
53 my ( $page, $label, $attr ) = @_;
54 param( 'current_page', $page );
55 my $url = self_url( -query => 1 );
58 qq|<li$attr><a href="$url" title="$page">$label</a></li>|;
62 $pager->previous_page ? li_a_href( $pager->previous_page, $prev ) : qq|<li class=skip>$prev</li>|
64 if ( $_ eq $pager->current_page ) {
65 qq|<li class=current_page>$_</li>|;
66 } elsif ( $_ eq '' ) {
67 qq|<li class=skip>...</li>|;
72 , $pager->next_page ? li_a_href( $pager->next_page, $next ) : qq|<li class=skip>$next</li>|
77 my $path = $ENV{PATH_INFO} || 'ecas';
79 $dir =~ s{/[^/]+.cgi}{};
81 my $config = YAML::LoadFile( "$dir/$path/config.yml" );
83 my $database = (keys %{ $config->{databases} })[0];
84 die "$database not in $path" unless $path =~ m{\Q$database\E};
86 my $html_markup = "$dir/$path/html.pm";
88 if ( -e $html_markup ) {
90 $html_markup = $database . '::html';
95 my $estraier = YAML::LoadFile( "$dir/../var/estraier/$database.yaml" );
97 my $db = $config->{databases}->{$database};
99 my @attr = keys %{ $estraier->{attr} }; # FIXME replace with real gnerated lookup
103 -title => $db->{name},
104 -style => '../../style.css',
107 qq|<div id=description>|, $db->{description}, qq|</div>|,
108 start_form( -action => self_url( query => 0 ) ),
111 -values => [ @attr ],
114 textfield( -name => 'search' ),
115 popup_menu( -name => 'attr_operator', -values => [ '', 'STRBW', 'STREQ' ],
117 '' => 'Bilo koja riječ',
118 'STRBW' => 'Početak',
119 'STREQ' => 'Točan oblik',
123 hidden( -name => 'entries_per_page', -default => $entries_per_page ),
124 hidden( -name => 'current_page', -default => 1 ),
125 checkbox( -name => 'debug', -default => 0 ), # FIXME hidden?
127 h2( 'Select input' ),
129 -name => 'only_input',
130 -values => [ map { $_->{name} } @{ $db->{input} } ],
137 dump_yaml( 'inputs', $db->{input} );
138 dump_yaml( 'input names', map { $_->{name} } @{ $db->{input} } );
142 if ( my $search = param('search') ) {
144 print qq|<div id="results">|;
146 my $node = Search::Estraier::Node->new(
147 url => $config->{hyperestraier}->{masterurl} . '/node/' . $database,
151 param( 'entries_per_page', $entries_per_page ) unless param('entries_per_page'); # FIXME not needed?
152 my $pager = Data::Page->new;
153 $pager->total_entries( param('current_page') * param('entries_per_page') );
154 $pager->$_( param($_) ) foreach ( qw/entries_per_page current_page/ );
156 dump_yaml( 'pager', $pager );
158 my $cond = Search::Estraier::Condition->new( debug => $debug );
159 $cond->set_phrase( $search );
160 $cond->set_skip( $pager->skipped );
161 $cond->set_max( $pager->entries_per_page );
163 if ( my $op = param('attr_operator') ) {
164 $cond->add_attr( param('attr') . " $op " . param('search') );
167 foreach my $i ( param('only_input') ) {
168 $cond->add_attr( '@uri STRBW file:///search/' . $database . '/' . $i );
172 my $nres = $node->search( $cond, 0 );
173 $pager->total_entries( $nres->hits );
175 dump_yaml( 'cond', $cond );
176 dump_yaml( 'nres', $nres );
179 my $no_results = "No results for search '%s'";
180 printf qq|<div class="error">$no_results</div>\n\n|, $search;
183 my $results = "%d results for search '%s' showing results %d - %d on page %d";
184 printf qq|<div class="message">$results</div>\n\n|, $nres->hits, $search, $pager->first, $pager->last, $pager->current_page;
186 my $pager_html = join("\n", show_pager( $pager ));
188 print qq|<ul class="pager">$pager_html</ul>\n\n| if $pager_html;
190 my $start = $pager->first;
191 print qq|<ol start=$start>\n|;
193 foreach my $i ( 1 .. $nres->doc_num ) {
194 my $rdoc = $nres->get_doc( $i - 1 );
196 foreach my $attr ( @attr ) {
197 my $v = $rdoc->attr( $attr );
198 if ( defined $v && $html_markup && ! $html_markup_skip->{$attr} ) {
199 eval "\$v = $html_markup->$attr( \$v );";
201 warn "disable html markup for $attr: $@";
202 $html_markup_skip->{$attr} = $@;
205 next unless defined $v;
206 print qq|<div><label>$attr</label><span class=$attr>$v</span></div>\n|;
212 print qq|<ul class="pager bottom">$pager_html</ul>\n\n| if $pager_html;
216 dump_yaml( 'pager', $pager );
220 dump_yaml( 'estraier', $estraier );
221 dump_yaml( 'db', $db );
222 dump_yaml( 'html_markup_skip', $html_markup_skip );