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

- refactoring, use hash $recipe with coderef instead of if-blocks

parent a9f0a42d
No related branches found
No related tags found
No related merge requests found
...@@ -7,62 +7,63 @@ sub prepare_aip_query ($opt) { ...@@ -7,62 +7,63 @@ sub prepare_aip_query ($opt) {
my @must; my @must;
my @must_not; my @must_not;
my @should; my @should;
if (exists $opt->{startrecord}) { my %recipe;
$recipe{startrecord} =sub {
$query->{from} = $opt->{startrecord} - 1; # start from index 0 -> first record $query->{from} = $opt->{startrecord} - 1; # start from index 0 -> first record
} };
if (exists $opt->{maxrecords}) { $recipe{maxrecords} =sub {
$query->{size} = $opt->{maxrecords}; $query->{size} = $opt->{maxrecords};
} };
if (exists $opt->{aip}) { $recipe{aip} =sub {
push @must, { push @must, {
"match_phrase" => { "match_phrase" => {
"uuid" => "$opt->{aip}" "uuid" => "$opt->{aip}"
} }
}; };
} };
if (exists $opt->{lzaid}) { $recipe{lzaid} =sub {
push @must, { push @must, {
"match_phrase" => { "match_phrase" => {
"transferMetadata.bim:bag-info_dict.bim:SLUBArchiv-lzaId" => "$opt->{lzaid}" "transferMetadata.bim:bag-info_dict.bim:SLUBArchiv-lzaId" => "$opt->{lzaid}"
} }
}; };
} };
if (exists $opt->{only_migrated}) { $recipe{only_migrated} =sub {
push @must, { push @must, {
"exists" => { "exists" => {
field => "transferMetadata.bim:bag-info_dict.bim:SLUBArchiv-migrated-AIP" field => "transferMetadata.bim:bag-info_dict.bim:SLUBArchiv-migrated-AIP"
} }
} }
} };
if (exists $opt->{only_updated}) { $recipe{only_updated} =sub {
push @must, { push @must, {
"exists" => { "exists" => {
field => "transferMetadata.bim:bag-info_dict.bim:SLUBArchiv-previous-AIP" field => "transferMetadata.bim:bag-info_dict.bim:SLUBArchiv-previous-AIP"
} }
} }
} };
if (exists $opt->{only_new}) { $recipe{only_new} =sub {
push @must_not, { push @must_not, {
"exists" => { "exists" => {
field => "transferMetadata.bim:bag-info_dict.bim:SLUBArchiv-previous-AIP" field => "transferMetadata.bim:bag-info_dict.bim:SLUBArchiv-previous-AIP"
} }
} }
} };
if (exists $opt->{only_ldp_project}) { $recipe{only_ldp_project} =sub {
push @must, { push @must, {
"match_phrase" => { "match_phrase" => {
"transferMetadata.bim:bag-info_dict.bim:LDP-project" => $opt->{only_ldp_project} "transferMetadata.bim:bag-info_dict.bim:LDP-project" => $opt->{only_ldp_project}
} }
} }
} };
if (exists $opt->{only_ldp_saxon}) { $recipe{only_ldp_saxon} =sub {
push @must, { push @must, {
"match_phrase" => { "match_phrase" => {
"transferMetadata.bim:bag-info_dict.bim:LDP-funder" => 'LDP Sachsen' "transferMetadata.bim:bag-info_dict.bim:LDP-funder" => 'LDP Sachsen'
} }
} }
} };
if (exists $opt->{only_ldp_without_saxon}) { $recipe{only_ldp_without_saxon} =sub {
push @must_not, { push @must_not, {
"match_phrase" => { "match_phrase" => {
"transferMetadata.bim:bag-info_dict.bim:LDP-funder" => 'LDP Sachsen' "transferMetadata.bim:bag-info_dict.bim:LDP-funder" => 'LDP Sachsen'
...@@ -73,22 +74,22 @@ sub prepare_aip_query ($opt) { ...@@ -73,22 +74,22 @@ sub prepare_aip_query ($opt) {
field => "transferMetadata.bim:bag-info_dict.bim:LDP-funder" field => "transferMetadata.bim:bag-info_dict.bim:LDP-funder"
} }
} }
} };
if (exists $opt->{only_ldp}) { $recipe{only_ldp} =sub {
push @must, { push @must, {
"exists" => { "exists" => {
field => "transferMetadata.bim:bag-info_dict.bim:LDP-funder" field => "transferMetadata.bim:bag-info_dict.bim:LDP-funder"
} }
} }
} };
if (exists $opt->{no_ldp}) { $recipe{no_ldp} =sub {
push @must_not, { push @must_not, {
"exists" => { "exists" => {
field => "transferMetadata.bim:bag-info_dict.bim:LDP-funder" field => "transferMetadata.bim:bag-info_dict.bim:LDP-funder"
} }
} }
} };
if (exists $opt->{descriptive}) { $recipe{descriptive} =sub {
#https://opster.com/guides/elasticsearch/search-apis/elasticsearch-match-multi-match-and-match-phrase-queries/#Multi-match-query #https://opster.com/guides/elasticsearch/search-apis/elasticsearch-match-multi-match-and-match-phrase-queries/#Multi-match-query
push @should, { push @should, {
"multi_match" => { "multi_match" => {
...@@ -96,8 +97,8 @@ sub prepare_aip_query ($opt) { ...@@ -96,8 +97,8 @@ sub prepare_aip_query ($opt) {
"fields" => ["transferMetadata.*"] # scan all metadata, exact match "fields" => ["transferMetadata.*"] # scan all metadata, exact match
} }
} }
} };
if (exists $opt->{fuzzy}) { $recipe{fuzzy} =sub {
push @should, { push @should, {
"multi_match" => { "multi_match" => {
"query" => "$opt->{fuzzy}", "query" => "$opt->{fuzzy}",
...@@ -105,8 +106,8 @@ sub prepare_aip_query ($opt) { ...@@ -105,8 +106,8 @@ sub prepare_aip_query ($opt) {
"type" => "phrase_prefix", "type" => "phrase_prefix",
} }
} }
} };
if (exists $opt->{creationdate_epochs}) { $recipe{creationdate_epochs} =sub {
push @must, { push @must, {
"range" => { "range" => {
"created" => { "created" => {
...@@ -115,40 +116,22 @@ sub prepare_aip_query ($opt) { ...@@ -115,40 +116,22 @@ sub prepare_aip_query ($opt) {
} }
} }
}; };
} };
if (exists $opt->{modificationdate}) { $recipe{modificationdate} =sub {
#push @queries, "FILE.objectCharacteristics.modificationDate==$opt->{modificationdate}"; #push @queries, "FILE.objectCharacteristics.modificationDate==$opt->{modificationdate}";
} };
if (exists $opt->{workflow}) { # LZA Workflow search $recipe{workflow} =sub { # LZA Workflow search
push @must, { push @must, {
"match_phrase" => { "match_phrase" => {
"transferMetadata.ObjectType_dict.Metadata_dict.WorkflowName" => $opt->{workflow} "transferMetadata.ObjectType_dict.Metadata_dict.WorkflowName" => $opt->{workflow}
} }
}; };
};
foreach my $key (keys %{ $opt } ) {
if (defined $recipe{$key} and ref $recipe{$key} eq 'CODE') {
$recipe{$key}->();
} }
if (exists $opt->{'with_format'}) {
#push @queries, "FILE.generalFileCharacteristics.formatLibraryId==$opt->{'with_format'}";
}
#if (exists $opt->{'without_format'}) {
# push @queries, "FILE.generalFileCharacteristics.formatLibraryId!=$opt->{'without_format'}";
#}
if (exists $opt->{'with_valid_files'}) {
#push @queries, "FILE.fileValidation.isValid==true";
}
if (exists $opt->{'with_invalid_files'}) {
#push @queries, "FILE.fileValidation.isValid==false";
}
if (exists $opt->{'with_passed_viruschecks'}) {
#push @queries, "FILE.fileVirusCheck.status==true";
}
if (exists $opt->{'with_failed_viruschecks'}) {
#push @queries, "FILE.fileVirusCheck.status==false";
}
if (exists $opt->{'with_missed_viruschecks'}) {
#push @queries, "FILE.fileVirusCheck.status==\"\"";
} }
#my $query = join(" and ", @queries);
if (scalar @must > 0) { if (scalar @must > 0) {
$query->{query}->{bool}->{must} = \@must ; $query->{query}->{bool}->{must} = \@must ;
} }
...@@ -244,7 +227,7 @@ sub prepare_ldpprojects_query { ...@@ -244,7 +227,7 @@ sub prepare_ldpprojects_query {
} }
}; };
$ldpprojects_query->{query}->{bool}->{must}=\@must; $ldpprojects_query->{query}->{bool}->{must}=\@must;
} };
return $ldpprojects_query; return $ldpprojects_query;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment