Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dariah
search
Commits
41981efd
Commit
41981efd
authored
Aug 26, 2021
by
Gradl, Tobias
Browse files
444: Prevent fallback to all collections if sourceId specified, but not
found (OPENED) Task-Url:
#444
parent
d93c14a9
Pipeline
#26397
passed with stage
in 40 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
search-core/src/main/java/eu/dariah/de/search/controller/search/QueryExecutionController.java
View file @
41981efd
...
...
@@ -26,7 +26,6 @@ import eu.dariah.de.search.query.Query;
import
eu.dariah.de.search.query.SimpleQuery
;
import
eu.dariah.de.search.query.SimpleQueryImpl
;
import
eu.dariah.de.search.query.execution.AggregationService
;
import
eu.dariah.de.search.query.execution.QueryExecutionServiceImpl
;
import
eu.dariah.de.search.query.results.QueryResult
;
import
eu.dariah.de.search.service.CustomSearchService
;
import
eu.dariah.de.search.service.DatamodelService
;
...
...
search-core/src/main/java/eu/dariah/de/search/controller/search/base/BaseSearchController.java
View file @
41981efd
...
...
@@ -56,14 +56,14 @@ public abstract class BaseSearchController extends BaseController {
protected
String
getCollectionSelectionDialog
(
@RequestBody
JsonNode
body
,
List
<
Collection
>
availableCollections
,
Locale
locale
,
Model
model
,
HttpServletRequest
request
)
{
ArrayNode
sourceIdsNode
=
(
ArrayNode
)
body
.
path
(
"sourceIds"
);
List
<
String
>
sourceIds
=
new
ArrayList
<
String
>();
List
<
String
>
sourceIds
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
sourceIdsNode
.
size
();
i
++)
{
sourceIds
.
add
(
sourceIdsNode
.
get
(
i
).
textValue
());
}
model
.
addAttribute
(
"collections"
,
collectionConverter
.
convert
(
availableCollections
,
locale
));
model
.
addAttribute
(
"preselectedCollIds"
,
sourceIds
);
model
.
addAttribute
(
"preselectAll"
,
sourceIds
.
size
()==
0
);
model
.
addAttribute
(
"preselectAll"
,
sourceIds
.
isEmpty
()
);
return
"search/sourceSelectionForm"
;
}
...
...
@@ -75,16 +75,15 @@ public abstract class BaseSearchController extends BaseController {
Map
<
String
,
String
>
collectionIdMap
=
collections
.
stream
().
collect
(
Collectors
.
toMap
(
Collection:
:
getColregEntityId
,
Collection:
:
getId
));
for
(
int
i
=
0
;
i
<
sourceIds
.
size
();
i
++)
{
if
(!
collectionIdMap
.
containsKey
(
sourceIds
.
get
(
i
)))
{
if
(!
notifications
.
contains
(
"~eu.dariah.de.minfba.search.view.notifications.selected_collection_unknown"
))
{
notifications
.
add
(
"~eu.dariah.de.minfba.search.view.notifications.selected_collection_unknown"
);
}
continue
;
}
if
(
strSourceId
.
length
()>
1
)
{
strSourceId
.
append
(
","
);
}
strSourceId
.
append
(
"\""
).
append
(
collectionIdMap
.
get
(
sourceIds
.
get
(
i
))).
append
(
"\""
);
if
(
collectionIdMap
.
containsKey
(
sourceIds
.
get
(
i
)))
{
strSourceId
.
append
(
"\""
).
append
(
collectionIdMap
.
get
(
sourceIds
.
get
(
i
))).
append
(
"\""
);
}
else
{
strSourceId
.
append
(
"\""
).
append
(
"cid:"
+
sourceIds
.
get
(
i
)).
append
(
"\""
);
}
}
}
...
...
search-core/src/main/java/eu/dariah/de/search/query/execution/QueryExecutionServiceImpl.java
View file @
41981efd
...
...
@@ -7,6 +7,8 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
org.elasticsearch.action.search.SearchResponse
;
import
org.elasticsearch.common.text.Text
;
import
org.elasticsearch.index.query.QueryBuilder
;
...
...
@@ -42,6 +44,7 @@ import eu.dariah.de.search.query.results.QueryResult;
import
eu.dariah.de.search.query.results.QueryResultDatasource
;
import
eu.dariah.de.search.query.results.ResultElement
;
import
lombok.extern.slf4j.Slf4j
;
import
net.bytebuddy.asm.Advice.This
;
import
eu.dariah.de.search.query.results.QueryResult.SearchTypes
;
@Slf4j
...
...
@@ -301,7 +304,7 @@ public class QueryExecutionServiceImpl extends BaseQueryService implements Query
if
(
responses
==
null
)
{
return
;
}
Map
<
String
,
Long
>
datasourceCountMap
=
new
HashMap
<
String
,
Long
>();
Map
<
String
,
Long
>
datasourceCountMap
=
new
HashMap
<>();
for
(
SearchResponse
resp
:
responses
)
{
if
(
resp
==
null
||
resp
.
getAggregations
()==
null
)
{
...
...
@@ -328,9 +331,14 @@ public class QueryExecutionServiceImpl extends BaseQueryService implements Query
}
}
List
<
QueryResultDatasource
>
resultProviders
=
new
ArrayList
<
QueryResultDatasource
>();
List
<
String
>
unknownSourceIds
=
new
ArrayList
<>();
if
(
q
.
getSourceIds
()!=
null
)
{
unknownSourceIds
.
addAll
(
q
.
getSourceIds
());
}
List
<
QueryResultDatasource
>
resultProviders
=
new
ArrayList
<>();
QueryResultDatasource
qrd
;
for
(
String
datasourceId
:
datasourceCountMap
.
keySet
())
{
for
(
String
datasourceId
:
datasourceCountMap
.
keySet
())
{
qrd
=
new
QueryResultDatasource
();
qrd
.
setHitCount
(
datasourceCountMap
.
get
(
datasourceId
));
qrd
.
setLoadTags
(
qrd
.
getHitCount
()>
0
);
...
...
@@ -341,14 +349,37 @@ public class QueryExecutionServiceImpl extends BaseQueryService implements Query
qrd
.
setProviderName
(
collectionService
.
findById
(
datasourceId
).
getName
(
"deu"
));
}
resultProviders
.
add
(
qrd
);
unknownSourceIds
.
remove
(
datasourceId
);
}
// Resolve entries that were unknown before (still are in UI) and can be replaced with actual datasources now
Map
<
String
,
String
>
resolvedIdsMap
=
this
.
resolveUnknownExternalIds
(
unknownSourceIds
);
for
(
Entry
<
String
,
String
>
resolvedIdsEntry
:
resolvedIdsMap
.
entrySet
())
{
qrd
=
new
QueryResultDatasource
();
if
(!
resolvedIdsEntry
.
getKey
().
equals
(
resolvedIdsEntry
.
getValue
()))
{
qrd
.
setHitCount
(
datasourceCountMap
.
get
(
resolvedIdsEntry
.
getValue
()));
qrd
.
setLoadTags
(
qrd
.
getHitCount
()>
0
);
qrd
.
setProviderId
(
resolvedIdsEntry
.
getKey
()
+
"~"
+
resolvedIdsEntry
.
getValue
());
Collection
ds
=
collectionService
.
findById
(
resolvedIdsEntry
.
getValue
());
if
(
ds
!=
null
)
{
qrd
.
setProviderName
(
collectionService
.
findById
(
resolvedIdsEntry
.
getValue
()).
getName
(
"deu"
));
}
}
else
{
qrd
.
setHitCount
(
0
);
qrd
.
setLoadTags
(
false
);
qrd
.
setProviderName
(
"unknown"
);
qrd
.
setProviderId
(
resolvedIdsEntry
.
getValue
());
}
resultProviders
.
add
(
qrd
);
}
Collections
.
sort
(
resultProviders
);
qr
.
setResultDatasources
(
resultProviders
);
}
private
void
addConfigInfo
(
Resource
r
,
List
<
Element
>
elems
)
{
// This should never be the case! Why is it happening
if
(
elems
==
null
)
{
...
...
@@ -375,3 +406,4 @@ public class QueryExecutionServiceImpl extends BaseQueryService implements Query
return
false
;
}
}
search-core/src/main/java/eu/dariah/de/search/query/execution/base/BaseQueryService.java
View file @
41981efd
...
...
@@ -17,6 +17,7 @@ import eu.dariah.de.search.Constants;
import
eu.dariah.de.search.Constants.QueryTypes
;
import
eu.dariah.de.search.Constants.RootElementKeys
;
import
eu.dariah.de.search.es.service.SearchService
;
import
eu.dariah.de.search.model.Collection
;
import
eu.dariah.de.search.model.ExtendedMappingContainer
;
import
eu.dariah.de.search.query.ExtendedQuery
;
import
eu.dariah.de.search.query.Query
;
...
...
@@ -208,6 +209,24 @@ public abstract class BaseQueryService extends BaseResultService {
return
this
.
wrapQueryBuilder
(
bqb
,
q
);
}
protected
Map
<
String
,
String
>
resolveUnknownExternalIds
(
List
<
String
>
sourceIds
)
{
Map
<
String
,
String
>
resolved
=
new
HashMap
<>(
sourceIds
.
size
());
Collection
resolvedC
;
for
(
String
sourceId
:
sourceIds
)
{
if
(
sourceId
.
contains
(
":"
))
{
resolvedC
=
collectionService
.
findByColregEntityId
(
sourceId
.
substring
(
sourceId
.
indexOf
(
":"
)+
1
));
if
(
resolvedC
!=
null
)
{
resolved
.
put
(
sourceId
,
resolvedC
.
getId
());
}
else
{
resolved
.
put
(
sourceId
,
sourceId
);
}
}
else
{
resolved
.
put
(
sourceId
,
sourceId
);
}
}
return
resolved
;
}
private
QueryBuilder
wrapQueryBuilder
(
QueryBuilder
bldr
,
Query
q
)
{
BoolQueryBuilder
boolQb
=
null
;
...
...
@@ -227,7 +246,7 @@ public abstract class BaseQueryService extends BaseResultService {
}
if
(
q
.
getSourceIds
()!=
null
&&
!
q
.
getSourceIds
().
isEmpty
())
{
boolQb
.
filter
(
QueryBuilders
.
termsQuery
(
Constants
.
ELEMENT_KEY_COLLECTION_ID
,
q
.
getSourceIds
()));
boolQb
.
filter
(
QueryBuilders
.
termsQuery
(
Constants
.
ELEMENT_KEY_COLLECTION_ID
,
this
.
resolveUnknownExternalIds
(
q
.
getSourceIds
())
.
values
())
);
}
}
...
...
i18n
@
cab8358d
Compare
864d677d
...
cab8358d
Subproject commit
864d677d7792539ec5f5331a3903497e3774999d
Subproject commit
cab8358d7ef4525e5d79ce56a58b2ffc4e3aac8e
resources
@
a761a623
Compare
32e1d5de
...
a761a623
Subproject commit
32e1d5ded7a30b738500748f2e07baeffb3019d3
Subproject commit
a761a6234188333500aecf32bb0dabe946e2705c
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment