13 |
|
|
14 |
my $range_around = 5; |
my $range_around = 5; |
15 |
my $entries_per_page = 30; |
my $entries_per_page = 30; |
16 |
|
my $debug = param('debug'); |
17 |
|
|
18 |
print header; |
print header( |
19 |
|
-charset => 'utf-8', |
20 |
|
); |
21 |
|
|
22 |
sub dump_yaml { |
sub dump_yaml { |
23 |
my $name = shift; |
my $name = shift; |
24 |
print qq|<pre># $name\n|, YAML::Dump( @_ ), qq|</pre>|; |
print qq|<pre># $name\n|, YAML::Dump( @_ ), qq|</pre>| if $debug; |
25 |
} |
} |
26 |
|
|
27 |
sub show_pager { |
sub show_pager { |
28 |
my ($pager,$coderef) = @_; |
my ($pager) = @_; |
29 |
|
|
30 |
my @show_pages; |
my @show_pages; |
31 |
my $after_current = 0; |
my $after_current = 0; |
43 |
push @show_pages, ( $pager->current_page + 1 .. $pager->current_page + $after_current + $range_around, '', $pager->last_page ); |
push @show_pages, ( $pager->current_page + 1 .. $pager->current_page + $after_current + $range_around, '', $pager->last_page ); |
44 |
} |
} |
45 |
|
|
46 |
dump_yaml( 'show_pages', \@show_pages ); |
# dump_yaml( 'show_pages', \@show_pages ); |
47 |
|
|
48 |
return '' unless $#show_pages; |
return '' unless $#show_pages; |
49 |
|
|
50 |
my ( $prev, $next ) = ( '<<', '>>' ); |
my ( $prev, $next ) = ( '<<', '>>' ); |
51 |
|
|
52 |
|
sub li_a_href { |
53 |
|
my ( $page, $label, $attr ) = @_; |
54 |
|
param( 'current_page', $page ); |
55 |
|
my $url = self_url( -query => 1 ); |
56 |
|
$attr ||= ''; |
57 |
|
$label ||= $page; |
58 |
|
qq|<li$attr><a href="$url" title="$page">$label</a></li>|; |
59 |
|
} |
60 |
|
|
61 |
return |
return |
62 |
$pager->previous_page ? $coderef->( $pager->previous_page, $prev ) : $prev |
$pager->previous_page ? li_a_href( $pager->previous_page, $prev ) : qq|<li class=skip>$prev</li>| |
63 |
, join( ' ', map { |
, ( map { |
64 |
if ( $_ == $pager->current_page ) { |
if ( $_ eq $pager->current_page ) { |
65 |
qq|<span class=current_page>$_</span>|; |
qq|<li class=current_page>$_</li>|; |
66 |
} elsif ( $_ eq '' ) { |
} elsif ( $_ eq '' ) { |
67 |
qq|<span class=skip>...</span>|; |
qq|<li class=skip>...</li>|; |
68 |
} else { |
} else { |
69 |
$coderef->( $_ ); |
li_a_href( $_ ); |
70 |
} |
} |
71 |
} @show_pages ) |
} @show_pages ) |
72 |
, $pager->next_page ? $coderef->( $pager->next_page, $next ) : $next |
, $pager->next_page ? li_a_href( $pager->next_page, $next ) : qq|<li class=skip>$next</li>| |
73 |
; |
; |
74 |
|
|
75 |
} |
} |
112 |
# -linebreak => 0, |
# -linebreak => 0, |
113 |
), |
), |
114 |
textfield( -name => 'search' ), |
textfield( -name => 'search' ), |
115 |
|
popup_menu( -name => 'attr_operator', -values => [ '', 'STRBW', 'STREQ' ], |
116 |
|
-labels => { |
117 |
|
'' => 'Bilo koja riječ', |
118 |
|
'STRBW' => 'Početak', |
119 |
|
'STREQ' => 'Točan oblik', |
120 |
|
}, |
121 |
|
), |
122 |
submit, |
submit, |
123 |
textfield( -name => 'entries_per_page', -default => $entries_per_page ), |
hidden( -name => 'entries_per_page', -default => $entries_per_page ), |
124 |
textfield( -name => 'current_page', -default => 1 ), |
hidden( -name => 'current_page', -default => 1 ), |
125 |
|
checkbox( -name => 'debug', -default => 0 ), # FIXME hidden? |
126 |
|
qq|<div id=inputs>|, |
127 |
|
h2( 'Select input' ), |
128 |
|
checkbox_group( |
129 |
|
-name => 'only_input', |
130 |
|
-values => [ map { $_->{name} } @{ $db->{input} } ], |
131 |
|
-linebreak=> 'true', |
132 |
|
), |
133 |
|
qq|</div>|, |
134 |
|
|
135 |
; |
; |
136 |
|
|
137 |
|
dump_yaml( 'inputs', $db->{input} ); |
138 |
|
dump_yaml( 'input names', map { $_->{name} } @{ $db->{input} } ); |
139 |
|
|
140 |
print end_form; |
print end_form; |
141 |
|
|
142 |
if ( my $search = param('search') ) { |
if ( my $search = param('search') ) { |
155 |
|
|
156 |
dump_yaml( 'pager', $pager ); |
dump_yaml( 'pager', $pager ); |
157 |
|
|
158 |
my $cond = Search::Estraier::Condition->new; |
my $cond = Search::Estraier::Condition->new( debug => $debug ); |
159 |
$cond->set_phrase( $search ); |
$cond->set_phrase( $search ); |
160 |
$cond->set_skip( $pager->skipped ); |
$cond->set_skip( $pager->skipped ); |
161 |
$cond->set_max( $pager->entries_per_page ); |
$cond->set_max( $pager->entries_per_page ); |
162 |
|
|
163 |
|
if ( my $op = param('attr_operator') ) { |
164 |
|
$cond->add_attr( param('attr') . " $op " . param('search') ); |
165 |
|
} |
166 |
|
|
167 |
|
foreach my $i ( param('only_input') ) { |
168 |
|
$cond->add_attr( '@uri STRBW file:///search/' . $database . '/' . $i ); |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
my $nres = $node->search( $cond, 0 ); |
my $nres = $node->search( $cond, 0 ); |
173 |
$pager->total_entries( $nres->hits ); |
$pager->total_entries( $nres->hits ); |
174 |
|
|
175 |
dump_yaml( 'cond', $cond ); |
dump_yaml( 'cond', $cond ); |
176 |
|
dump_yaml( 'nres', $nres ); |
177 |
|
|
178 |
if ( ! $nres ) { |
if ( ! $nres ) { |
179 |
my $no_results = "No results for search '%s'"; |
my $no_results = "No results for search '%s'"; |
180 |
printf qq|<div class="error">$no_results</div>|, $search; |
printf qq|<div class="error">$no_results</div>\n\n|, $search; |
181 |
} else { |
} else { |
182 |
|
|
183 |
my $results = "Got %d results for search '%s'"; |
my $results = "%d results for search '%s' showing results %d - %d on page %d"; |
184 |
printf qq|<div class="message">$results</div>|, $nres->hits, $search; |
printf qq|<div class="message">$results</div>\n\n|, $nres->hits, $search, $pager->first, $pager->last, $pager->current_page; |
185 |
|
|
186 |
print |
my $pager_html = join("\n", show_pager( $pager )); |
187 |
qq|<div class=pager>|, |
|
188 |
join(' ', show_pager( $pager, |
print qq|<ul class="pager">$pager_html</ul>\n\n| if $pager_html; |
|
sub { |
|
|
my ($page,$label) = @_; |
|
|
param( 'current_page', $page ); |
|
|
my $url = self_url( -query => 1 ); |
|
|
$label = $page unless defined $label; |
|
|
qq|<a href="$url">$label</a>|; |
|
|
} |
|
|
)), |
|
|
qq|</div>| |
|
|
; |
|
189 |
|
|
190 |
my $start = $pager->first; |
my $start = $pager->first; |
191 |
print qq|<ol start=$start>|; |
print qq|<ol start=$start>\n|; |
192 |
|
|
193 |
foreach my $i ( 1 .. $nres->doc_num ) { |
foreach my $i ( 1 .. $nres->doc_num ) { |
194 |
my $rdoc = $nres->get_doc( $i - 1 ); |
my $rdoc = $nres->get_doc( $i - 1 ); |
207 |
} |
} |
208 |
print qq|</li>\n|; |
print qq|</li>\n|; |
209 |
} |
} |
210 |
print qq|</ol>|; |
print qq|</ol>\n\n|; |
211 |
|
|
212 |
|
print qq|<ul class="pager bottom">$pager_html</ul>\n\n| if $pager_html; |
213 |
} |
} |
214 |
print qq|</div>|; |
print qq|</div>|; |
215 |
|
|