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

- add get_headers() to fix bug missed headers if first result does not contain field

parent 6aa2649b
Branches
Tags
No related merge requests found
......@@ -478,8 +478,8 @@ sub execute {
print_humanreadable_report(\%results);
} else {
my ($headers, $table) = prepare_for_table(\%results, \@ldp_projects);
if ($opt->{output_format} eq 'output_as_rsv') {SLUB::LZA::TA::Output::RSV::print_results($headers, $table);}
elsif ($opt->{output_format} eq 'output_as_csv') {SLUB::LZA::TA::Output::CSV::print_results($headers, $table);}
if ($opt->{output_format} eq 'output_as_rsv') {SLUB::LZA::TA::Output::RSV::print_results($table);}
elsif ($opt->{output_format} eq 'output_as_csv') {SLUB::LZA::TA::Output::CSV::print_results($table);}
elsif ($opt->{output_format} eq 'output_as_raw') { SLUB::LZA::TA::Output::Raw::print_results(\%results);}
}
say STDERR "report is already sent to STDOUT.";
......
......@@ -83,6 +83,16 @@ sub line_result_mapper {
return \%line;
}
sub get_headers($result_ref) {
my %tmpheaders;
foreach my $line (@{$result_ref}) {
foreach my $k (keys %{ $line }) {
$tmpheaders{$k}=1;
}
};
my @headers = sort keys (%tmpheaders);
return \@headers;
}
sub print_results ($aips_response, $opt) {
# print pagination to STDERR
......@@ -91,6 +101,7 @@ sub print_results ($aips_response, $opt) {
my $to = $all > $opt->{maxrecords} ? ($opt->{maxrecords} + $from -1) : ($all + $from -1);
my $idx = $from;
my @result = map {
my $tmp_new = line_result_mapper($_, $opt);
if (defined $opt->{with_result_index}) {
......@@ -98,7 +109,7 @@ sub print_results ($aips_response, $opt) {
}
$tmp_new;
} @{$aips_response->{hits}->{hits}};
my @headers = sort keys %{$result[0]};
my $aip_only = List::Util::none {$_ =~ m/^with/} keys %{$opt};
if (!exists $opt->{output_format}) {
if ($aip_only) {
......@@ -114,9 +125,9 @@ sub print_results ($aips_response, $opt) {
say STDERR "reporting results". ($from != $to ? " $from$to " : " ")."$output_format_human";
}
if ($opt->{output_format} eq 'output_as_csv') {
SLUB::LZA::TA::Output::CSV::print_results(\@headers, \@result);
SLUB::LZA::TA::Output::CSV::print_results(\@result);
} elsif ($opt->{output_format} eq 'output_as_rsv') {
SLUB::LZA::TA::Output::RSV::print_results(\@headers, \@result);
SLUB::LZA::TA::Output::RSV::print_results(\@result);
} elsif ($opt->{output_format} eq 'output_as_raw') {
SLUB::LZA::TA::Output::Raw::print_results($aips_response);
}
......
......@@ -8,7 +8,8 @@ use namespace::autoclean -except => qr{SLUB::LZA::TA::.*};
# ABSTRACT: search IEs module for ta-tool
sub print_results($headers_ref, $result_ref) {
sub print_results($result_ref) {
my $headers_ref = SLUB::LZA::TA::Output::get_headers($result_ref);
binmode(STDOUT, ':encoding(UTF-8)');
say join(",", map {
my $l = $_;
......
......@@ -14,7 +14,8 @@ use namespace::autoclean -except => qr{SLUB::LZA::TA::.*};
# ABSTRACT: search IEs module for ta-tool
sub print_results($header_ref, $result_ref) {
sub print_results($result_ref) {
my $header_ref = SLUB::LZA::TA::Output::get_headers($result_ref);
binmode(STDOUT, ':bytes');
print join(CHR_VALUE_TERMINATOR, map {
my $l = $_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment