added category filtering and pagination for classified pages endpoint

This commit is contained in:
2026-09-26 18:08:21 +02:00
parent 347c7ae520
commit 2ba4a12a20
2 changed files with 17 additions and 3 deletions
+16 -2
View File
@@ -256,7 +256,7 @@ async def get_classified_pages_aggs(org_url: str,institution_id: str = DEFAULT_I
buckets = response.get("aggregations", {}).get("categories", {}).get("buckets", [])
return [CategoryBucket(category=bucket["key"], count=bucket["doc_count"]) for bucket in buckets]
async def get_classified_pages(org_url: str,institution_id: str = DEFAULT_INSTITUTION_ID,) -> list[ClassifiedPage]:
async def get_classified_pages(org_url: str,institution_id: str = DEFAULT_INSTITUTION_ID,category: str | None = None,page: int = 1,size: int = 10) -> list[ClassifiedPage]:
"""
Returns the classified pages of the orgminer org.
"""
@@ -277,7 +277,21 @@ async def get_classified_pages(org_url: str,institution_id: str = DEFAULT_INSTIT
"minimum_should_match": 1
}
}
if category:
query["bool"]["filter"] = [
{
"term": {
"category.keyword": category
}
}
]
body = {
"query": query,
"from": (page - 1) * size,
"size": size,
}
index = resolve_urls_categorized_es_index(institution_id)
response = await search(query=query,index=index,cluster=ESCluster.INSE)
response = await search(body=body,index=index,cluster=ESCluster.INSE)
classified_pages = [ClassifiedPage.from_es_hit(hit) for hit in response["hits"]["hits"]]
return classified_pages
+1 -1
View File
@@ -124,4 +124,4 @@ async def get_classified_pages(
institution_id = _get_account_institution_id(session, access_token_metadata.effective_account_id)
if not institution_id:
institution_id = DEFAULT_INSTITUTION_ID
return await logic.get_classified_pages(org_url,full_institution_url(institution_id))
return await logic.get_classified_pages(org_url=org_url,institution_id=full_institution_url(institution_id),category=category,page=page,size=size)