Commit 45facd26 authored by Alvin Noe Ladines's avatar Alvin Noe Ladines
Browse files

Merge branch 'v0.7.5' of gitlab.mpcdf.mpg.de:nomad-lab/nomad-FAIR into archive_api

parents d309d00f ec128098
Pipeline #68910 passed with stages
in 14 minutes and 42 seconds
......@@ -207,6 +207,8 @@ class Api {
this.onStartLoading = () => null
this.onFinishLoading = () => null
this.statistics = {}
this._swaggerClient = Swagger(`${apiBase}/swagger.json`)
this.keycloak = keycloak
......@@ -389,6 +391,29 @@ class Api {
...search}))
.catch(handleApiError)
.then(response => response.body)
.then(response => {
// fill absent statistics values with values from prior searches
// this helps to keep consistent values, e.g. in the metadata search view
if (response.statistics) {
const empty = {}
Object.keys(response.statistics.total.all).forEach(metric => empty[metric] = 0)
Object.keys(response.statistics)
.filter(key => !['total', 'authors', 'atoms'].includes(key))
.forEach(key => {
if (!this.statistics[key]) {
this.statistics[key] = new Set()
}
const values = this.statistics[key]
Object.keys(response.statistics[key]).forEach(value => values.add(value))
values.forEach(value => {
if (!response.statistics[key][value]) {
response.statistics[key][value] = empty
}
})
})
}
return response
})
.finally(this.onFinishLoading)
}
......
......@@ -193,8 +193,6 @@ class DomainQuantity:
0 (the default) means no aggregations.
metric: Indicates that this quantity should be used as search metric. Values need
to be tuples with metric name and elastic aggregation (e.g. sum, cardinality)
zero_aggs: Return aggregation values for values with zero hits in the search. Default
is with zero aggregations.
elastic_mapping: An optional elasticsearch_dsl mapping. Default is ``Keyword``.
elastic_search_type: An optional elasticsearch search type. Default is ``term``.
elastic_field: An optional elasticsearch key. Default is the name of the quantity.
......@@ -206,8 +204,7 @@ class DomainQuantity:
def __init__(
self, description: str = None, multi: bool = False, aggregations: int = 0,
order_default: bool = False, metric: Tuple[str, str] = None,
zero_aggs: bool = True, metadata_field: str = None,
elastic_mapping: type = None,
metadata_field: str = None, elastic_mapping: type = None,
elastic_search_type: str = 'term', elastic_field: str = None,
elastic_value: Callable[[Any], Any] = None,
argparse_action: str = 'append'):
......@@ -218,7 +215,6 @@ class DomainQuantity:
self.order_default = order_default
self.aggregations = aggregations
self.metric = metric
self.zero_aggs = zero_aggs
self.elastic_mapping = elastic_mapping
self.elastic_search_type = elastic_search_type
self.metadata_field = metadata_field
......
......@@ -274,7 +274,7 @@ Domain(
order_default=True),
atoms=DomainQuantity(
'The atom labels of all atoms in the simulated system.',
aggregations=len(ase.data.chemical_symbols), multi=True, zero_aggs=False),
aggregations=len(ase.data.chemical_symbols), multi=True),
only_atoms=DomainQuantity(
'The atom labels concatenated in species-number order. Used with keyword search '
'to facilitate exclusive searches.',
......
......@@ -440,10 +440,7 @@ class SearchRequest:
The basic doc_count metric ``code_runs`` is always given.
"""
quantity = quantities[quantity_name]
min_doc_count = 0 if quantity.zero_aggs else 1
terms = A(
'terms', field=quantity.elastic_field, size=size, min_doc_count=min_doc_count,
order=dict(_key='asc'))
terms = A('terms', field=quantity.elastic_field, size=size, order=dict(_key='asc'))
buckets = self._search.aggs.bucket('statistics:%s' % quantity_name, terms)
self._add_metrics(buckets, metrics_to_use)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment