update comment

This commit is contained in:
2025-03-21 13:11:03 -03:00
parent 36b97b1291
commit 85deafc08f
8 changed files with 82 additions and 314 deletions

View File

@@ -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],
}