Skip to content
Snippets Groups Projects
Commit 1977558d authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- added --with-result-index

- fixed debug output (use stderr)
- added pagination support
- added more descriptive result output for humans on stderr
parent 8bb04c70
No related branches found
No related tags found
No related merge requests found
...@@ -86,6 +86,7 @@ sub opt_spec { ...@@ -86,6 +86,7 @@ sub opt_spec {
[ 'with-ldp-project' => 'also returns AIP ldp-project'], [ 'with-ldp-project' => 'also returns AIP ldp-project'],
[ 'with-location' => 'also returns AIP location' ], [ 'with-location' => 'also returns AIP location' ],
[ 'with-path' => 'also returns AIP path' ], [ 'with-path' => 'also returns AIP path' ],
[ 'with-result-index' => 'also returns result index' ],
[ 'with-score' => 'also returns score of Elastic Search match (higher => better)' ], [ 'with-score' => 'also returns score of Elastic Search match (higher => better)' ],
[ 'with-size' => 'also returns AIP size' ], [ 'with-size' => 'also returns AIP size' ],
[ 'with-slubarchiv-archivalvaluedescription|with-archival-value-description' => 'also returns AIP slubarchiv-archivalvaluedescription'], [ 'with-slubarchiv-archivalvaluedescription|with-archival-value-description' => 'also returns AIP slubarchiv-archivalvaluedescription'],
...@@ -215,6 +216,7 @@ sub find_aips_by_file_pronom_id { ...@@ -215,6 +216,7 @@ sub find_aips_by_file_pronom_id {
} }
}, },
"size" => 10000,
"_source" => { "_source" => {
"includes" => 'AIPUUID' "includes" => 'AIPUUID'
} }
...@@ -257,9 +259,10 @@ sub execute { ...@@ -257,9 +259,10 @@ sub execute {
} }
if (exists $opt->{debug}) { if (exists $opt->{debug}) {
use Data::Printer; use Data::Printer;
say "------------------------"; say STDERR "query:";
say "query=",np( $aips_query); say STDERR "------------------------";
say "------------------------"; say STDERR np( $aips_query);
say STDERR "------------------------";
} }
#p($aips_query); #p($aips_query);
$aips_response = SLUB::LZA::TA::Archivematica::Elasticsearch::query_elasticsearch( $aips_response = SLUB::LZA::TA::Archivematica::Elasticsearch::query_elasticsearch(
...@@ -269,9 +272,20 @@ sub execute { ...@@ -269,9 +272,20 @@ sub execute {
'aips', # indexname 'aips', # indexname
$aips_query, # query_hash ref $aips_query, # query_hash ref
); );
#p($aips_response);
# print pagination to STDERR
my $all = $aips_response->{hits}->{total};
my $from = $opt->{startrecord} || 1;
my $to = $all > $opt->{maxrecords} ? $opt->{maxrecords} : $all;
my $idx = $from;
my @result = map { my @result = map {
line_result_mapper($_, $opt); my $tmp_new = line_result_mapper($_, $opt);
if (defined $opt->{with_result_index}) {
$tmp_new->{_idx} = $idx++;
}
$tmp_new;
} @{$aips_response->{hits}->{hits}}; } @{$aips_response->{hits}->{hits}};
my @headers = sort keys %{$result[0]}; my @headers = sort keys %{$result[0]};
my $aip_only = List::Util::none {$_ =~ m/^with/} keys %{$opt}; my $aip_only = List::Util::none {$_ =~ m/^with/} keys %{$opt};
...@@ -283,7 +297,11 @@ sub execute { ...@@ -283,7 +297,11 @@ sub execute {
$opt->{output_format} = 'output_as_rsv'; $opt->{output_format} = 'output_as_rsv';
} }
} }
say STDERR "found $all result" . ($all != 1 ? 's' : '');
if ($all > 0) {
my $output_format_human = $opt->{output_format}; $output_format_human =~ s/_/ /g;
say STDERR "reporting results". ($from != $to ? " $from$to " : " ")."$output_format_human";
}
if ($opt->{output_format} eq 'output_as_csv') { if ($opt->{output_format} eq 'output_as_csv') {
binmode(STDOUT, ':encoding(UTF-8)'); binmode(STDOUT, ':encoding(UTF-8)');
say join(",", @headers); say join(",", @headers);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment