in search/cloud-function/python/vertex_ai_search_client.py [0:0]
def map_search_pager_to_dict(self, pager: SearchPager) -> dict[str, Any]:
"""
Maps a SearchPager to a dictionary structure, iterativly requesting results.
https://cloud.google.com/python/docs/reference/discoveryengine/latest/google.cloud.discoveryengine_v1alpha.services.search_service.pagers.SearchPager
Args:
pager (SearchPager): The pager returned by the search method.
Returns:
Dict[str, Any]: A dictionary containing the search results and metadata.
"""
output: dict[str, Any] = {
"results": [
SearchResponse.SearchResult.to_dict(result) for result in pager
],
"total_size": pager.total_size,
"attribution_token": pager.attribution_token,
"next_page_token": pager.next_page_token,
"corrected_query": pager.corrected_query,
"facets": [],
"applied_controls": [],
}
if pager.summary:
output["summary"] = SearchResponse.Summary.to_dict(pager.summary)
if pager.facets:
output["facets"] = [
SearchResponse.Facet.to_dict(facet) for facet in pager.facets
]
if pager.guided_search_result:
output["guided_search_result"] = SearchResponse.GuidedSearchResult.to_dict(
pager.guided_search_result
)
if pager.query_expansion_info:
output["query_expansion_info"] = SearchResponse.QueryExpansionInfo.to_dict(
pager.query_expansion_info
)
if pager.applied_controls:
output["applied_controls"] = [
control.strip() for control in pager.applied_controls
]
return output