Skip to content

Commit b7323be

Browse files
committed
feat(document): add parameter support to document retrieval
- add `params` parameter to `Document.retrieve()` method - create new `RetrieveParameters` typed dictionary - support including/excluding fields when retrieving documents
1 parent 36b25b2 commit b7323be

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/typesense/document.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
DeleteSingleDocumentParameters,
2727
DirtyValuesParameters,
2828
DocumentSchema,
29+
RetrieveParameters,
2930
)
3031

3132
if sys.version_info >= (3, 11):
@@ -67,7 +68,7 @@ def __init__(
6768
self.collection_name = collection_name
6869
self.document_id = document_id
6970

70-
def retrieve(self) -> TDoc:
71+
def retrieve(self, params: RetrieveParameters) -> TDoc:
7172
"""
7273
Retrieve this specific document.
7374
@@ -78,6 +79,7 @@ def retrieve(self) -> TDoc:
7879
endpoint=self._endpoint_path,
7980
entity_type=typing.Dict[str, str],
8081
as_json=True,
82+
params=params,
8183
)
8284
return response
8385

src/typesense/types/document.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,3 +889,16 @@ class DeleteResponse(typing.TypedDict):
889889
"""
890890

891891
num_deleted: int
892+
893+
894+
class RetrieveParameters(typing.TypedDict):
895+
"""
896+
Parameters for retrieving documents.
897+
898+
Attributes:
899+
include_fields (str): Fields to include in the retrieved documents.
900+
exclude_fields (str): Fields to exclude from the retrieved documents.
901+
"""
902+
903+
include_fields: typing.NotRequired[typing.Union[str, typing.List[str]]]
904+
exclude_fields: typing.NotRequired[typing.Union[str, typing.List[str]]]

0 commit comments

Comments
 (0)