diff --git a/gui/src/components/search/UploadersList.js b/gui/src/components/search/UploadersList.js index f350aa60792127a7523a4b7a5f59de5bdc1b4fc7..b786317b8b5404242b8a502f825ef506968bf19c 100644 --- a/gui/src/components/search/UploadersList.js +++ b/gui/src/components/search/UploadersList.js @@ -21,8 +21,7 @@ class UploadersList extends React.Component { static contextType = SearchContext.type componentDidMount() { - const {state: {query}, setQuery, setStatisticsToRefresh} = this.context - setQuery({...query, statistics_order: '_count'}) + const {setStatisticsToRefresh} = this.context setStatisticsToRefresh('uploader') } diff --git a/nomad/app/api/repo.py b/nomad/app/api/repo.py index 3840905b308f975c8af8d3dc9755315d49543d51..b4afa11a5801716508d8f31b05a619e3e01a7e37 100644 --- a/nomad/app/api/repo.py +++ b/nomad/app/api/repo.py @@ -113,8 +113,6 @@ _search_request_parser.add_argument( 'Possible values are %s.' % ', '.join(search_extension.metrics.keys()))) _search_request_parser.add_argument( 'statistics', type=bool, help=('Return statistics.')) -_search_request_parser.add_argument( - 'statistics_order', type=str, help='Statistics order (can be _key or _count)') _search_request_parser.add_argument( 'exclude', type=str, action='split', help='Excludes the given keys in the returned data.') for group_name in search_extension.groups: @@ -203,7 +201,6 @@ class RepoCalcsResource(Resource): with_statistics = args.get('statistics', False) or \ any(args.get(group_name, False) for group_name in search_extension.groups) - statistics_order = args.get('statistics_order', '_key') except Exception as e: abort(400, message='bad parameters: %s' % str(e)) @@ -233,7 +230,7 @@ class RepoCalcsResource(Resource): abort(400, message='there is no metric %s' % metric) if with_statistics: - search_request.default_statistics(metrics_to_use=metrics, statistics_order=statistics_order) + search_request.default_statistics(metrics_to_use=metrics) additional_metrics = [ group_quantity.metric_name diff --git a/nomad/datamodel/datamodel.py b/nomad/datamodel/datamodel.py index 0d7dfa499d27fe228b2eb7ee4dffb037bf884170..f648ad6bbe441a126cb49267c0ee1dfe4e290411 100644 --- a/nomad/datamodel/datamodel.py +++ b/nomad/datamodel/datamodel.py @@ -351,7 +351,8 @@ class EntryMetadata(metainfo.MSection): description='Search uploader with exact names.', metric_name='uploaders', metric='cardinality', many_or='append', search_field='uploader.name.keyword', - default_statistic=True, statistic_size=10), + default_statistic=True, statistic_size=10, + statistic_order='_count'), Search( name='uploader_id', search_field='uploader.user_id') ]) diff --git a/nomad/datamodel/dft.py b/nomad/datamodel/dft.py index cc98d82857d4c0afa5be2c3d11d7fb164c752320..2c50207609495b602e36d44b9146ab11327e5913 100644 --- a/nomad/datamodel/dft.py +++ b/nomad/datamodel/dft.py @@ -259,12 +259,16 @@ class DFTMetadata(MSection): labels_springer_compound_class = Quantity( type=str, shape=['0..*'], description='Springer compund classification.', - a_search=Search(many_and='append', default_statistic=True, statistic_size=10)) + a_search=Search( + many_and='append', default_statistic=True, statistic_size=10, + statistic_order='_count')) labels_springer_classification = Quantity( type=str, shape=['0..*'], description='Springer classification by property.', - a_search=Search(many_and='append', default_statistic=True, statistic_size=10)) + a_search=Search( + many_and='append', default_statistic=True, statistic_size=10, + statistic_order='_count')) optimade = SubSection( sub_section=OptimadeEntry, diff --git a/nomad/metainfo/search_extension.py b/nomad/metainfo/search_extension.py index 2d83ac00a0cb8c5588694ee313fc1b11183d1059..3442c4b7abd6aa5726bc92213d4dafa4c4bb4dbd 100644 --- a/nomad/metainfo/search_extension.py +++ b/nomad/metainfo/search_extension.py @@ -64,6 +64,9 @@ class Search(Elastic): default_statistic: Indicates this quantity to be part of the default statistics. statistics_size: The maximum number of values in a statistic. Default is 10. + statistics_order: + The order key that is passed to elastic search to determine the order of + the statistic values. group: Indicates that his quantity can be used to group results. The value will be the name of the group. search_field: The qualified field in the elastic mapping that is used to search. @@ -81,6 +84,7 @@ class Search(Elastic): group: str = None, metric: str = None, metric_name: str = None, default_statistic: bool = False, statistic_size: int = 10, + statistic_order: str = '_key', derived: Callable[[Any], Any] = None, search_field: str = None, **kwargs): @@ -97,6 +101,7 @@ class Search(Elastic): self.metric = metric self.metric_name = metric_name self.statistic_size = statistic_size + self.statistic_order = statistic_order self.search_field = search_field self.derived = derived diff --git a/nomad/search.py b/nomad/search.py index 894f313ae364614f832e396afd05630fe40fb009..f141248e299fb61e83481fe7a35de505f6597a27 100644 --- a/nomad/search.py +++ b/nomad/search.py @@ -281,25 +281,23 @@ class SearchRequest: self._add_metrics(self._search.aggs, metrics_to_use) return self - def default_statistics(self, metrics_to_use: List[str] = [], statistics_order: str = '_key'): + def default_statistics(self, metrics_to_use: List[str] = []): ''' Configures the domain's default statistics. ''' - mode = 'desc' - if statistics_order == '_key': - mode = 'asc' - order = {statistics_order: mode} - for search_quantity in default_statistics[self._domain]: + statistic_order = search_quantity.statistic_order self.statistic( search_quantity.qualified_name, search_quantity.statistic_size, metrics_to_use=metrics_to_use, - order=order) + order={statistic_order: 'asc' if statistic_order == '_key' else 'desc'}) return self - def statistic(self, quantity_name: str, size: int, metrics_to_use: List[str] = [], order: Dict[str, str] = dict(_key='asc')): + def statistic( + self, quantity_name: str, size: int, metrics_to_use: List[str] = [], + order: Dict[str, str] = dict(_key='asc')): ''' This can be used to display statistics over the searched entries and allows to implement faceted search on the top values for each quantity. @@ -323,6 +321,7 @@ class SearchRequest: metrics_to_use: The metrics calculated over the aggregations. Can be ``unique_code_runs``, ``datasets``, other domain specific metrics. The basic doc_count metric ``code_runs`` is always given. + order: The order dictionary is passed to the elastic search aggregation. ''' quantity = search_quantities[quantity_name] terms = A('terms', field=quantity.search_field, size=size, order=order)