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
nomad-lab
nomad-FAIR
Commits
fc13085f
Commit
fc13085f
authored
Feb 10, 2020
by
Markus Scheidgen
Browse files
Exclude unnecessary fields from the search results.
parent
2b4b3485
Pipeline
#68892
failed with stages
in 14 minutes and 59 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
gui/src/components/api.js
View file @
fc13085f
...
...
@@ -384,7 +384,9 @@ class Api {
async
search
(
search
)
{
this
.
onStartLoading
()
return
this
.
swagger
()
.
then
(
client
=>
client
.
apis
.
repo
.
search
(
search
))
.
then
(
client
=>
client
.
apis
.
repo
.
search
({
exclude
:
[
'
atoms
'
,
'
only_atoms
'
,
'
files
'
,
'
quantities
'
,
'
optimade
'
,
'
labels
'
,
'
geometries
'
],
...
search
}))
.
catch
(
handleApiError
)
.
then
(
response
=>
response
.
body
)
.
finally
(
this
.
onFinishLoading
)
...
...
nomad/app/api/repo.py
View file @
fc13085f
...
...
@@ -84,6 +84,8 @@ _search_request_parser.add_argument(
'Possible values are %s.'
%
', '
.
join
(
datamodel
.
Domain
.
instance
.
metrics_names
)))
_search_request_parser
.
add_argument
(
'statistics'
,
type
=
bool
,
help
=
(
'Return statistics.'
))
_search_request_parser
.
add_argument
(
'exclude'
,
type
=
str
,
action
=
'split'
,
help
=
'Excludes the given keys in the returned data.'
)
for
group_name
in
search
.
groups
:
_search_request_parser
.
add_argument
(
group_name
,
type
=
bool
,
help
=
(
'Return %s group data.'
%
group_name
))
...
...
@@ -150,8 +152,9 @@ class RepoCalcsResource(Resource):
"""
try
:
parsed_args
=
_search_request_parser
.
parse_args
()
args
=
{
key
:
value
for
key
,
value
in
_search_request_parser
.
parse_args
()
.
items
()
key
:
value
for
key
,
value
in
parse
d
_args
.
items
()
if
value
is
not
None
}
scroll
=
args
.
get
(
'scroll'
,
False
)
...
...
@@ -202,6 +205,9 @@ class RepoCalcsResource(Resource):
elif
len
(
metrics
)
>
0
:
search_request
.
totals
(
metrics_to_use
=
metrics
)
if
'exclude'
in
parsed_args
:
search_request
.
exclude
(
*
parsed_args
[
'exclude'
])
try
:
if
scroll
:
results
=
search_request
.
execute_scrolled
(
scroll_id
=
scroll_id
,
size
=
per_page
)
...
...
nomad/search.py
View file @
fc13085f
...
...
@@ -543,6 +543,11 @@ class SearchRequest:
return
self
def
exclude
(
self
,
*
args
):
""" Exclude certain elastic keys from the search results. """
self
.
_search
=
self
.
_search
.
source
(
excludes
=
args
)
return
self
def
execute
(
self
):
"""
Exectutes without returning actual results. Only makes sense if the request
...
...
tests/app/test_api.py
View file @
fc13085f
...
...
@@ -881,6 +881,14 @@ class TestRepo():
assert
len
(
statistics
[
'system'
])
==
1
assert
value
in
statistics
[
'system'
]
def
test_search_exclude
(
self
,
api
,
example_elastic_calcs
,
no_warn
):
rv
=
api
.
get
(
'/repo/?exclude=atoms,only_atoms'
)
assert
rv
.
status_code
==
200
result
=
json
.
loads
(
rv
.
data
)[
'results'
][
0
]
assert
'atoms'
not
in
result
assert
'only_atoms'
not
in
result
assert
'basis_set'
in
result
metrics_permutations
=
[[],
search
.
metrics_names
]
+
[[
metric
]
for
metric
in
search
.
metrics_names
]
def
test_search_admin
(
self
,
api
,
example_elastic_calcs
,
no_warn
,
admin_user_auth
):
...
...
tests/test_search.py
View file @
fc13085f
...
...
@@ -137,6 +137,14 @@ def test_search_totals(elastic, example_search_data):
assert
'quantities'
not
in
results
def
test_search_excludes
(
elastic
,
example_search_data
):
for
item
in
SearchRequest
().
execute_paginated
()[
'results'
]:
assert
'atoms'
in
item
for
item
in
SearchRequest
().
exclude
(
'atoms'
).
execute_paginated
()[
'results'
]:
assert
'atoms'
not
in
item
@
pytest
.
mark
.
parametrize
(
"order_by"
,
[
None
,
'upload_id'
])
def
test_search_quantity
(
elastic
,
normalized
:
parsing
.
LocalBackend
,
test_user
:
datamodel
.
User
,
...
...
Write
Preview
Markdown
is supported
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