Skip to content

Commit

Permalink
Boolean ES data added to search query
Browse files Browse the repository at this point in the history
Jason Munro committed Jul 1, 2021

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 3e19048 commit 816a58c
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/mp_api/routes/search/query_operators.py
Original file line number Diff line number Diff line change
@@ -141,6 +141,38 @@ def ensure_indexes(self): # pragma: no cover
return [("theoretical", False)]


class SearchESQuery(QueryOperator):
"""
Method to generate a query on search electronic structure data.
"""

def query(
self,
is_gap_direct: Optional[bool] = Query(
None, description="Whether a band gap is direct or not."
),
is_metal: Optional[bool] = Query(
None, description="Whether the material is considered a metal."
),
) -> STORE_PARAMS:

crit = defaultdict(dict) # type: dict

if is_gap_direct is not None:
crit["is_gap_direct"] = is_gap_direct

if is_metal is not None:
crit["is_metal"] = is_metal

return {"criteria": crit}

def ensure_indexes(self): # pragma: no cover

keys = ["is_gap_direct", "is_metal"]

return [(key, False) for key in keys]


class SearchStatsQuery(QueryOperator):
"""
Method to generate a query on search stats data
2 changes: 2 additions & 0 deletions src/mp_api/routes/search/resources.py
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@
SearchIsTheoreticalQuery,
SearchMagneticQuery,
SearchStatsQuery,
SearchESQuery,
)


@@ -36,6 +37,7 @@ def search_resource(search_store):
SearchIsStableQuery(),
SearchIsTheoreticalQuery(),
SearchMagneticQuery(),
SearchESQuery(),
NumericQuery(model=SearchDoc, excluded_fields=["composition"]),
HasPropsQuery(),
DeprecationQuery(),

0 comments on commit 816a58c

Please sign in to comment.