22 |
|
|
23 |
sub dump_yaml { |
sub dump_yaml { |
24 |
my $name = shift; |
my $name = shift; |
25 |
print qq|<pre># $name\n|, YAML::Dump( @_ ), qq|</pre>| if $debug; |
print qq|<div class=dump><tt>$name</tt><pre>|, YAML::Dump( @_ ), qq|</pre></div>| if $debug; |
26 |
} |
} |
27 |
|
|
28 |
sub show_pager { |
sub show_pager { |
76 |
} |
} |
77 |
|
|
78 |
my $path = $ENV{PATH_INFO} || 'ecas'; |
my $path = $ENV{PATH_INFO} || 'ecas'; |
79 |
|
$path =~ s{^/+}{}; |
80 |
|
$path =~ s{/+$}{}; |
81 |
my $dir = $0; |
my $dir = $0; |
82 |
$dir =~ s{/[^/]+.cgi}{}; |
$dir =~ s{/[^/]+.cgi}{}; |
83 |
|
|
84 |
|
dump_yaml( 'dir', $dir ); |
85 |
|
|
86 |
my $config = YAML::LoadFile( "$dir/$path/config.yml" ); |
my $config = YAML::LoadFile( "$dir/$path/config.yml" ); |
87 |
|
|
88 |
my $database = (keys %{ $config->{databases} })[0]; |
my $database = (keys %{ $config->{databases} })[0]; |
97 |
undef $html_markup; |
undef $html_markup; |
98 |
} |
} |
99 |
|
|
100 |
my $estraier = YAML::LoadFile( "$dir/../var/estraier/$database.yaml" ); |
my $stats; |
101 |
|
{ |
102 |
|
my $path = "$dir/../var/swish/$database.yaml"; |
103 |
|
$stats = YAML::LoadFile( $path ); |
104 |
|
dump_yaml( "stats $path", $stats ); |
105 |
|
} |
106 |
|
|
107 |
my $db = $config->{databases}->{$database}; |
my $db = $config->{databases}->{$database}; |
108 |
|
|
109 |
my @attr = keys %{ $estraier->{attr} }; # FIXME replace with real gnerated lookup |
my @attr = keys %{ $stats->{attr} }; # FIXME replace with real gnerated lookup |
110 |
|
|
111 |
# XXX pipe delimit list! |
# XXX pipe delimit list! |
112 |
my $select_attr_operators = << '__ATTR_OPERATORS__'; |
my $select_attr_operators = << '__ATTR_OPERATORS__'; |
137 |
|
|
138 |
warn "## only_input = ", dump( $only_input ); |
warn "## only_input = ", dump( $only_input ); |
139 |
|
|
140 |
|
my @style = ( '../../style.css' ); |
141 |
|
push @style, "../../$path/$path.css" if -e "$dir/$path/$path.css"; |
142 |
|
dump_yaml( 'style', \@style ); |
143 |
|
|
144 |
print |
print |
145 |
start_html( |
start_html( |
146 |
-title => $db->{name}, |
-title => $db->{name}, |
147 |
-style => '../../style.css', |
-style => [ @style ], |
148 |
), |
), |
149 |
h1( $db->{name} ), |
h1( $db->{name} ), |
150 |
qq|<div id=description>|, $db->{description}, qq|</div>|, |
qq|<div id=description>|, $db->{description}, qq|</div>|, |
158 |
popup_menu( -name => 'attr_operator', %$attr_operator ), |
popup_menu( -name => 'attr_operator', %$attr_operator ), |
159 |
submit, |
submit, |
160 |
hidden( -name => 'entries_per_page', -default => $entries_per_page ), |
hidden( -name => 'entries_per_page', -default => $entries_per_page ), |
161 |
hidden( -name => 'current_page', -default => 1 ), |
# we need current_page fixed at 1 so that every submit through form will reset it |
162 |
|
qq|<input type=hidden name=current_page value=1 >|, |
163 |
checkbox( -name => 'debug', -default => 0 ), # FIXME hidden? |
checkbox( -name => 'debug', -default => 0 ), # FIXME hidden? |
164 |
qq|<div id=inputs>|, |
qq|<div id=inputs>|, |
165 |
h2( 'Select input' ), |
h2( 'Select input' ), |
172 |
|
|
173 |
; |
; |
174 |
|
|
|
dump_yaml( 'inputs', $db->{input} ); |
|
|
dump_yaml( 'input names', map { $_->{name} } @{ $db->{input} } ); |
|
|
|
|
175 |
print end_form; |
print end_form; |
176 |
|
|
177 |
if ( my $search = param('search') ) { |
if ( my $search = param('search') ) { |
181 |
my $swish = SWISH::API->new( "$dir/../var/swish/$database" ); |
my $swish = SWISH::API->new( "$dir/../var/swish/$database" ); |
182 |
$swish->abort_last_error if $swish->Error; |
$swish->abort_last_error if $swish->Error; |
183 |
|
|
|
param( 'entries_per_page', $entries_per_page ) unless param('entries_per_page'); # FIXME not needed? |
|
184 |
my $pager = Data::Page->new; |
my $pager = Data::Page->new; |
|
$pager->total_entries( param('current_page') * param('entries_per_page') ); |
|
185 |
$pager->$_( param($_) ) foreach ( qw/entries_per_page current_page/ ); |
$pager->$_( param($_) ) foreach ( qw/entries_per_page current_page/ ); |
186 |
|
|
187 |
dump_yaml( 'pager', $pager ); |
dump_yaml( 'pager', $pager ); |
225 |
|
|
226 |
$pager->total_entries( $swish_results->hits ); |
$pager->total_entries( $swish_results->hits ); |
227 |
|
|
228 |
|
$swish_results->seek_result( $pager->first ); |
229 |
|
|
230 |
if ( ! $pager->total_entries ) { |
if ( ! $pager->total_entries ) { |
231 |
my $no_results = 'No results for search <b>%s</b>'; |
my $no_results = 'No results for search <b>%s</b>'; |
232 |
$no_results = $swish->error_string . '<br><b>%s</b>' if $swish->error; |
$no_results = $swish->error_string . '<br><b>%s</b>' if $swish->error; |
243 |
my $start = $pager->first; |
my $start = $pager->first; |
244 |
print qq|<ol start=$start>\n|; |
print qq|<ol start=$start>\n|; |
245 |
|
|
246 |
|
my $limit = $pager->entries_on_this_page; |
247 |
|
|
248 |
while ( my $result = $swish_results->next_result ) { |
while ( my $result = $swish_results->next_result ) { |
249 |
|
last if $limit-- == 0; |
250 |
|
|
251 |
my $data = from_json $result->property('data'); |
my $data = from_json $result->property('data'); |
252 |
|
|
253 |
|
dump_yaml( 'data', $data ); |
254 |
|
|
255 |
print qq|<li>|; |
print qq|<li>|; |
256 |
foreach my $attr ( @attr ) { |
foreach my $attr ( @attr ) { |
257 |
next unless defined $data->{$attr}; |
next unless defined $data->{$attr}; |
277 |
|
|
278 |
} |
} |
279 |
|
|
280 |
dump_yaml( 'db', $db ); |
dump_yaml( "config databases $database", $db ); |
281 |
dump_yaml( 'html_markup_skip', $html_markup_skip ); |
dump_yaml( 'html_markup_skip', $html_markup_skip ); |
282 |
|
|
283 |
print end_html; |
print end_html; |