update comment
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import math
|
||||
from typing import Any
|
||||
from typing import TypedDict
|
||||
|
||||
from elasticsearch import Elasticsearch
|
||||
from elasticsearch_dsl import Search
|
||||
@@ -7,13 +7,19 @@ from elasticsearch_dsl import Search
|
||||
MAX_PAGE_SIZE = 100
|
||||
|
||||
|
||||
class PaginatedResult(TypedDict):
|
||||
total_items: int
|
||||
total_pages: int
|
||||
items: list[dict]
|
||||
|
||||
|
||||
def search(
|
||||
index: str,
|
||||
*,
|
||||
query: dict,
|
||||
page_size: int = 25,
|
||||
elastic_client: Elasticsearch,
|
||||
) -> dict[str, Any]:
|
||||
) -> PaginatedResult:
|
||||
s = Search(
|
||||
using=elastic_client,
|
||||
index=index,
|
||||
@@ -36,5 +42,5 @@ def search(
|
||||
return {
|
||||
'total_items': r.hits.total.value, # type: ignore
|
||||
'total_pages': math.ceil(r.hits.total.value / page_size), # type: ignore
|
||||
'hits': [hit.to_dict() for hit in r],
|
||||
'items': [hit.to_dict() for hit in r],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user