Skip to content

Commit

Permalink
Update hint schemes and has_props query
Browse files Browse the repository at this point in the history
  • Loading branch information
munrojm committed Nov 8, 2023
1 parent 847c891 commit 0ec549d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
45 changes: 39 additions & 6 deletions emmet-api/emmet/api/routes/materials/materials/hint_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,43 @@ class MaterialsHintScheme(HintScheme):
"""

def generate_hints(self, query):
for param in query["criteria"]:
if "composition_reduced" in param:
return {"hint": {"composition_reduced.$**": 1}}
elif "nelements" in param:
return {"hint": {"nelements": 1}}
hints = {"count_hint": {"deprecated": 1, "builder_meta.license": 1}}
hints["agg_hint"] = hints["count_hint"]

return {"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
):
hints["count_hint"] = {
"deprecated": 1,
"builder_meta.license": 1,
"formula_pretty": 1,
"material_id": 1,
param: 1,
}
hints["agg_hint"] = hints["count_hint"]
break

elif query.get("sort", {}):
for param in query["sort"]:
if param not in [
"deprecated",
"builder_meta.license",
"material_id",
"formula_pretty",
]:
hints["agg_hint"] = {
"deprecated": 1,
"builder_meta.license": 1,
"formula_pretty": 1,
"material_id": 1,
param: 1,
}

return hints
12 changes: 8 additions & 4 deletions emmet-api/emmet/api/routes/materials/summary/hint_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ def generate_hints(self, query):

if list(query.get("criteria").keys()) != ["deprecated", "builder_meta.license"]:
for param in query["criteria"]:
if param not in [
"deprecated",
"builder_meta.license",
]:
if (
param
not in [
"deprecated",
"builder_meta.license",
]
and "has_props" not in param
):
hints["count_hint"] = {
"deprecated": 1,
"builder_meta.license": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ def query(
crit = {}

if has_props:
crit = {
"has_props": {"$all": [prop.strip() for prop in has_props.split(",")]}
}
for entry in [prop.strip() for prop in has_props.split(",")]:
crit[f"has_props.{entry}"] = True

return {"criteria": crit}

Expand Down

0 comments on commit 0ec549d

Please sign in to comment.