From 70094f38cbe03178cc9fc2b8c33211252a3834b8 Mon Sep 17 00:00:00 2001 From: Jason Munro Date: Thu, 16 Nov 2023 17:46:14 -0800 Subject: [PATCH] Fix has props and composition in hint (#895) * Fix has props and composition in hint * Fix hint scheme test * Small hint scheme bugs --- .../routes/materials/summary/hint_scheme.py | 33 +++++++++++-------- .../materials/summary/test_hint_scheme.py | 4 +-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/emmet-api/emmet/api/routes/materials/summary/hint_scheme.py b/emmet-api/emmet/api/routes/materials/summary/hint_scheme.py index 5012653cd1..75e7ad5a01 100644 --- a/emmet-api/emmet/api/routes/materials/summary/hint_scheme.py +++ b/emmet-api/emmet/api/routes/materials/summary/hint_scheme.py @@ -11,20 +11,25 @@ def generate_hints(self, query): hints["agg_hint"] = hints["count_hint"] if list(query.get("criteria").keys()) != ["deprecated", "builder_meta.license"]: - for param in query["criteria"]: - if param not in [ - "deprecated", - "builder_meta.license", - ] and ("has_props" not in param and "composition_reduced" not in param): - hints["count_hint"] = { - "deprecated": 1, - "builder_meta.license": 1, - "formula_pretty": 1, - "material_id": 1, - param: 1, - } - hints["agg_hint"] = hints["count_hint"] - break + pure_params = [param.split(".")[0] for param in query["criteria"]] + + if "has_props" in pure_params: + hints["count_hint"] = {"has_props.$**": 1} + elif "composition_reduced" in pure_params: + hints["count_hint"] = {"composition_reduced.$**": 1} + else: + for param in pure_params: + if param not in ["deprecated", "builder_meta"]: + hints["count_hint"] = { + "deprecated": 1, + "builder_meta.license": 1, + "formula_pretty": 1, + "material_id": 1, + param: 1, + } + break + + hints["agg_hint"] = hints["count_hint"] elif query.get("sort", {}): for param in query["sort"]: diff --git a/emmet-api/tests/materials/summary/test_hint_scheme.py b/emmet-api/tests/materials/summary/test_hint_scheme.py index 83f7bb8626..f8e3617143 100644 --- a/emmet-api/tests/materials/summary/test_hint_scheme.py +++ b/emmet-api/tests/materials/summary/test_hint_scheme.py @@ -38,8 +38,8 @@ def test_summary_hint_scheme(): "sort": {"energy_above_hull": 1}, } ) == { - "count_hint": {"deprecated": 1, "builder_meta.license": 1}, - "agg_hint": {"deprecated": 1, "builder_meta.license": 1}, + "count_hint": {"has_props.$**": 1}, + "agg_hint": {"has_props.$**": 1}, } assert scheme.generate_hints( {