Skip to content

Commit 5b3aacb

Browse files
committed
refactor(multi-search): format multi-search class based on linting rules
1 parent b2c8c18 commit 5b3aacb

1 file changed

Lines changed: 60 additions & 3 deletions

File tree

src/typesense/multi_search.py

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
"""
2+
This module provides functionality for performing multi-search operations in the Typesense API.
3+
4+
It contains the MultiSearch class, which allows for executing multiple search queries
5+
in a single API call.
6+
7+
Classes:
8+
MultiSearch: Manages multi-search operations in the Typesense API.
9+
10+
Dependencies:
11+
- typesense.api_call: Provides the ApiCall class for making API requests.
12+
- typesense.preprocess:
13+
Provides the stringify_search_params function for parameter processing.
14+
- typesense.types.document:
15+
Provides the MultiSearchCommonParameters type.
16+
- typesense.types.multi_search:
17+
Provides MultiSearchRequestSchema and MultiSearchResponse types.
18+
19+
Note: This module uses conditional imports to support both Python 3.11+ and earlier versions.
20+
"""
21+
122
import sys
223

324
from typesense.api_call import ApiCall
@@ -11,24 +32,60 @@
1132
import typing_extensions as typing
1233

1334

14-
class MultiSearch(object):
15-
RESOURCE_PATH = "/multi_search"
35+
class MultiSearch:
36+
"""
37+
Manages multi-search operations in the Typesense API.
38+
39+
This class provides methods to perform multiple search queries in a single API call.
40+
41+
Attributes:
42+
RESOURCE_PATH (str): The API endpoint path for multi-search operations.
43+
api_call (ApiCall): The ApiCall instance for making API requests.
44+
"""
45+
46+
resource_path: typing.Final[str] = "/multi_search"
1647

1748
def __init__(self, api_call: ApiCall) -> None:
49+
"""
50+
Initialize the MultiSearch instance.
51+
52+
Args:
53+
api_call (ApiCall): The ApiCall instance for making API requests.
54+
"""
1855
self.api_call = api_call
1956

2057
def perform(
2158
self,
2259
search_queries: MultiSearchRequestSchema,
2360
common_params: typing.Union[MultiSearchCommonParameters, None] = None,
2461
) -> MultiSearchResponse:
62+
"""
63+
Perform a multi-search operation.
64+
65+
This method allows executing multiple search queries in a single API call.
66+
It processes the search parameters, sends the request to the Typesense API,
67+
and returns the multi-search response.
68+
69+
Args:
70+
search_queries (MultiSearchRequestSchema):
71+
A dictionary containing the list of search queries to perform.
72+
The dictionary should have a 'searches' key with a list of search
73+
parameter dictionaries.
74+
common_params (Union[MultiSearchCommonParameters, None], optional):
75+
Common parameters to apply to all search queries. Defaults to None.
76+
77+
Returns:
78+
MultiSearchResponse:
79+
The response from the multi-search operation, containing
80+
the results of all search queries.
81+
"""
2582
stringified_search_params = [
2683
stringify_search_params(search_params)
2784
for search_params in search_queries.get("searches")
2885
]
2986
search_body = {"searches": stringified_search_params}
3087
response: MultiSearchResponse = self.api_call.post(
31-
MultiSearch.RESOURCE_PATH,
88+
MultiSearch.resource_path,
3289
body=search_body,
3390
params=common_params,
3491
as_json=True,

0 commit comments

Comments
 (0)