Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tools for technical analysts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Digital Preservation
tools for technical analysts
Commits
84c0715b
Commit
84c0715b
authored
1 year ago
by
Andreas Romeyke
Browse files
Options
Downloads
Patches
Plain Diff
- 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
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/SLUB/LZA/TA/Archivematica/Elasticsearch/PrepareQuery.pm
+40
-57
40 additions, 57 deletions
lib/SLUB/LZA/TA/Archivematica/Elasticsearch/PrepareQuery.pm
with
40 additions
and
57 deletions
lib/SLUB/LZA/TA/Archivematica/Elasticsearch/PrepareQuery.pm
+
40
−
57
View file @
84c0715b
...
@@ -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
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment