Skip to content

Portals API Reference

backend.app.api.endpoints.portals

Portals summary endpoint backed by the OpenSearch summary index.

get_portals_summary() async

Return portal summaries sorted by dataset count.

Source code in backend/app/api/endpoints/portals.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@router.get("/api/v1/portals")
async def get_portals_summary():
    """Return portal summaries sorted by dataset count."""
    try:
        client = get_client()
        response = client.search(
            index=AUCTUS_PORTALS_INDEX_NAME,
            body={
                "query": {"match_all": {}},
                "sort": [{"dataset_count": {"order": "desc"}}],
                "size": 100,
            },
        )

        hits = response.get("hits", {}).get("hits", [])
        portals = []
        for hit in hits:
            source = hit.get("_source", {}) or {}
            portals.append(
                {
                    "domain": source.get("domain"),
                    "display_label": source.get("display_label") or source.get("domain"),
                    "dataset_count": int(source.get("dataset_count", 0) or 0),
                }
            )

        return {"portals": portals}
    except NotFoundError:
        logger.warning("Portal summary index %s not found; returning defaults", AUCTUS_PORTALS_INDEX_NAME)
        return {"portals": DEFAULT_PORTALS}
    except Exception as exc:
        logger.warning("Portal summary query failed: %s", exc)
        return {"portals": DEFAULT_PORTALS}