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
2ec7fdf4
Commit
2ec7fdf4
authored
Jul 30, 2019
by
Markus Scheidgen
Browse files
Added authors and comments to search.
parent
64e58cf2
Changes
5
Hide whitespace changes
Inline
Side-by-side
gui/src/components/search/SearchBar.js
View file @
2ec7fdf4
...
...
@@ -127,9 +127,19 @@ class SearchBar extends React.Component {
const
{
data
:
{
quantities
}
}
=
this
.
props
const
suggestions
=
[]
Object
.
keys
(
quantities
).
forEach
(
quantity
=>
{
// filter out pseudo quantity total
const
quantityKeys
=
Object
.
keys
(
quantities
).
filter
(
quantity
=>
quantity
!==
'
total
'
)
// put authors to the end
const
authorIndex
=
quantityKeys
.
indexOf
(
'
authors
'
)
if
(
authorIndex
>=
0
)
{
quantityKeys
[
authorIndex
]
=
quantityKeys
.
splice
(
quantityKeys
.
length
-
1
,
1
,
quantityKeys
[
authorIndex
])[
0
]
}
quantityKeys
.
forEach
(
quantity
=>
{
Object
.
keys
(
quantities
[
quantity
]).
forEach
(
quantityValue
=>
{
if
(
quantityValue
.
toLowerCase
().
startsWith
(
value
))
{
const
quantityValueLower
=
quantityValue
.
toLowerCase
()
if
(
quantityValueLower
.
startsWith
(
value
)
||
(
quantity
===
'
authors
'
&&
quantityValueLower
.
includes
(
value
)))
{
suggestions
.
push
({
key
:
quantity
,
value
:
quantityValue
...
...
@@ -138,6 +148,12 @@ class SearchBar extends React.Component {
})
})
// Always add as comment to the end of suggestions
suggestions
.
push
({
key
:
'
comment
'
,
value
:
value
})
return
suggestions
}
...
...
nomad/api/repo.py
View file @
2ec7fdf4
...
...
@@ -17,6 +17,7 @@ The repository API of the nomad@FAIRDI APIs. Currently allows to resolve reposit
meta-data.
"""
from
typing
import
List
from
flask_restplus
import
Resource
,
abort
,
fields
from
flask
import
request
,
g
from
elasticsearch_dsl
import
Q
...
...
@@ -110,7 +111,7 @@ repo_request_parser.add_argument(
repo_request_parser
.
add_argument
(
'scroll_id'
,
type
=
str
,
help
=
'The id of the current scrolling window to use.'
)
repo_request_parser
.
add_argument
(
'metrics'
,
type
=
str
,
help
=
(
'metrics'
,
type
=
str
,
action
=
'append'
,
help
=
(
'Metrics to aggregate over all quantities and their values as comma separated list. '
'Possible values are %s.'
%
', '
.
join
(
search
.
metrics_names
)))
...
...
@@ -213,16 +214,11 @@ class RepoCalcsResource(Resource):
page
=
int
(
request
.
args
.
get
(
'page'
,
1
))
per_page
=
int
(
request
.
args
.
get
(
'per_page'
,
10
if
not
scroll
else
1000
))
order
=
int
(
request
.
args
.
get
(
'order'
,
-
1
))
metrics_str
=
request
.
args
.
get
(
'metrics'
,
''
)
metrics
:
List
[
str
]
=
request
.
args
.
getlist
(
'metrics'
)
from_time
=
rfc3339DateTime
.
parse
(
request
.
args
.
get
(
'from_time'
,
'2000-01-01'
))
until_time_str
=
request
.
args
.
get
(
'until_time'
,
None
)
until_time
=
rfc3339DateTime
.
parse
(
until_time_str
)
if
until_time_str
is
not
None
else
datetime
.
datetime
.
utcnow
()
time_range
=
(
from_time
,
until_time
)
metrics
=
[
metric
for
metric
in
metrics_str
.
split
(
','
)
if
metric
in
search
.
metrics_names
]
except
Exception
:
abort
(
400
,
message
=
'bad parameter types'
)
...
...
@@ -237,6 +233,10 @@ class RepoCalcsResource(Resource):
if
order
not
in
[
-
1
,
1
]:
abort
(
400
,
message
=
'invalid pagination'
)
for
metric
in
metrics
:
if
metric
not
in
search
.
metrics_names
:
abort
(
400
,
message
=
'there is not metric %s'
%
metric
)
q
=
create_owner_query
()
# TODO this should be removed after migration
...
...
@@ -263,8 +263,8 @@ class RepoCalcsResource(Resource):
return
results
,
200
except
search
.
ScrollIdNotFound
:
abort
(
400
,
'The given scroll_id does not exist.'
)
except
KeyError
as
e
:
abort
(
400
,
str
(
e
))
#
except KeyError as e:
#
abort(400, str(e))
repo_quantity_values_model
=
api
.
model
(
'RepoQuantityValues'
,
{
...
...
nomad/datamodel/base.py
View file @
2ec7fdf4
...
...
@@ -230,7 +230,7 @@ class Domain:
base_quantities
=
dict
(
authors
=
DomainQuantity
(
elastic_field
=
'authors.name.keyword'
,
multi
=
True
,
elastic_field
=
'authors.name.keyword'
,
multi
=
True
,
aggregations
=
1000
,
description
=
(
'Search for the given author. Exact keyword matches in the form "Lastname, '
'Firstname".'
)),
...
...
@@ -322,7 +322,7 @@ class Domain:
"""
return
{
quantity
.
name
:
quantity
.
aggregations
for
quantity
in
self
.
quantities
.
values
()
for
quantity
in
self
.
search_
quantities
.
values
()
if
quantity
.
aggregations
>
0
}
...
...
nomad/search.py
View file @
2ec7fdf4
...
...
@@ -507,7 +507,8 @@ def metrics_search(
order
=
dict
(
_key
=
'asc'
))
buckets
=
search
.
aggs
.
bucket
(
quantity_name
,
terms
)
add_metrics
(
buckets
)
if
quantity_name
not
in
[
'authors'
]:
add_metrics
(
buckets
)
add_metrics
(
search
.
aggs
)
...
...
@@ -517,6 +518,7 @@ def metrics_search(
result
=
{
metric
:
bucket
[
metric
][
'value'
]
for
metric
in
metrics_to_use
if
hasattr
(
bucket
,
metric
)
}
result
.
update
(
code_runs
=
code_runs
)
return
result
...
...
tests/test_api.py
View file @
2ec7fdf4
...
...
@@ -783,8 +783,8 @@ class TestRepo():
@
pytest
.
mark
.
parametrize
(
'metrics'
,
metrics_permutations
)
def
test_search_total_metrics
(
self
,
client
,
example_elastic_calcs
,
no_warn
,
metrics
):
rv
=
client
.
get
(
'/repo/?
metrics=%s'
%
','
.
join
(
metrics
))
assert
rv
.
status_code
==
200
rv
=
client
.
get
(
'/repo/?
%s'
%
urlencode
(
dict
(
metrics
=
metrics
),
doseq
=
True
))
assert
rv
.
status_code
==
200
,
str
(
rv
.
data
)
data
=
json
.
loads
(
rv
.
data
)
total_metrics
=
data
.
get
(
'quantities'
,
{}).
get
(
'total'
,
{}).
get
(
'all'
,
None
)
assert
total_metrics
is
not
None
...
...
@@ -794,14 +794,17 @@ class TestRepo():
@
pytest
.
mark
.
parametrize
(
'metrics'
,
metrics_permutations
)
def
test_search_aggregation_metrics
(
self
,
client
,
example_elastic_calcs
,
no_warn
,
metrics
):
rv
=
client
.
get
(
'/repo/?
metrics=%s'
%
','
.
join
(
metrics
))
rv
=
client
.
get
(
'/repo/?
%s'
%
urlencode
(
dict
(
metrics
=
metrics
),
doseq
=
True
))
assert
rv
.
status_code
==
200
data
=
json
.
loads
(
rv
.
data
)
for
quantit
ies
in
data
.
get
(
'quantities'
).
value
s
():
for
metrics_result
in
quantit
ies
.
values
():
for
name
,
quantit
y
in
data
.
get
(
'quantities'
).
item
s
():
for
metrics_result
in
quantit
y
.
values
():
assert
'code_runs'
in
metrics_result
for
metric
in
metrics
:
assert
metric
in
metrics_result
if
name
!=
'authors'
:
for
metric
in
metrics
:
assert
metric
in
metrics_result
else
:
assert
len
(
metrics_result
)
==
1
# code_runs is the only metric for authors
@
pytest
.
mark
.
parametrize
(
'n_results, page, per_page'
,
[(
2
,
1
,
5
),
(
1
,
1
,
1
),
(
0
,
2
,
3
)])
def
test_search_pagination
(
self
,
client
,
example_elastic_calcs
,
no_warn
,
n_results
,
page
,
per_page
):
...
...
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