Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions emmet-api/emmet/api/query_operator/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
from emmet.api.query_operator import QueryOperator
from emmet.api.utils import STORE_PARAMS

DEFAULT_LIMIT: int = 100
MAX_LIMIT: int = 1000


class AtlasPaginationQuery(QueryOperator):
"""Query operators to provides pagination for Atlas Search queries."""

def __init__(self, default_limit: int = 100, max_limit: int = 1000):
def __init__(self, default_limit: int = DEFAULT_LIMIT, max_limit: int = MAX_LIMIT):
"""
Args:
default_limit: the default number of documents to return
Expand Down Expand Up @@ -71,7 +74,7 @@ def meta(self) -> dict:
class PaginationQuery(QueryOperator):
"""Query operators to provides Pagination."""

def __init__(self, default_limit: int = 100, max_limit: int = 1000):
def __init__(self, default_limit: int = DEFAULT_LIMIT, max_limit: int = MAX_LIMIT):
"""
Args:
default_limit: the default number of documents to return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from emmet.api.query_operator.dynamic import NumericQuery
from emmet.api.query_operator import (
NumericQuery,
PaginationQuery,
SortQuery,
SparseFieldsQuery,
)
from emmet.api.resource import ReadOnlyResource
from emmet.core.electrode import InsertionElectrodeDoc
from emmet.api.core.global_header import GlobalHeaderProcessor

from emmet.api.query_operator import PaginationQuery, SparseFieldsQuery
from emmet.api.routes.materials.insertion_electrodes.query_operators import (
ElectrodeFormulaQuery,
ElectrodeElementsQuery,
Expand All @@ -14,6 +18,17 @@

from emmet.api.core.settings import MAPISettings

sort_fields = [
"max_delta_volume",
"average_voltage",
"capacity_grav",
"capacity_vol",
"energy_grav",
"energy_vol",
"stability_charge",
"stability_discharge",
]


def insertion_electrodes_resource(insertion_electrodes_store):
resource = ReadOnlyResource(
Expand All @@ -31,6 +46,7 @@ def insertion_electrodes_resource(insertion_electrodes_store):
InsertionElectrodeDoc,
default_fields=["battery_id", "last_updated"],
),
SortQuery(fields=sort_fields, max_num=1),
],
header_processor=GlobalHeaderProcessor(),
tags=["Materials Electrodes"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class RoboTextSearchQuery(QueryOperator):
"""
Method to generate a robocrystallographer text search query
Method to generate a robocrystallographer text search query.
"""

def query(
Expand All @@ -32,7 +32,7 @@ def query(
"path": "description",
"allowAnalyzedField": True,
},
"sort": {"score": {"$meta": "searchScore"}, "description": 1},
"sort": {"score": {"$meta": "searchScore"}, "material_id": 1},
"count": {"type": "total"},
}
},
Expand Down
Loading