Example #1
0
    async def search_for_url(cls, *, search_index: SearchIndex,
                             base_url: str) -> AlgoliaMetadata:
        """Create an AlgoliaMetadata from a base documentation url."""
        request_options = {
            "filters":
            f"baseUrl:{cls.escape_facet_value(base_url)}",
            "attributesToRetrieve": [
                "handle",
                "h1",
                "description",
                "series",
                "contentType",
            ],
        }
        results = search_index.search("", request_options)
        if len(results["hits"]) == 0:
            raise ValueError(f"Algolia record unavailable for {base_url}")

        hit = results["hits"][0]
        return cls(
            title=hit["h1"],
            description=hit["description"],
            series=hit["series"],
            handle=hit["handle"],
            content_type=hit["contentType"],
        )
Example #2
0
def list_remote_keys(index: SearchIndex) -> List[str]:
    """handle pagination eventually..."""
    all_object_ids: Set[str] = set()
    params = {"attributesToRetrieve": "objectID", "hitsPerPage": 100}
    first_page = index.search("", params)
    first_page_hits = hit_object_ids(first_page)
    all_object_ids.update(first_page_hits)

    page_count = first_page["nbPages"]
    for i in range(1, page_count):
        next_page = index.search("", dict(params, page=i))
        if next_page["nbHits"] <= 0:
            break
        next_page_hits = hit_object_ids(next_page["hits"])
        all_object_ids.update(next_page_hits)

    return list(all_object_ids)