Skip to content

Commit df2f6f6

Browse files
committed
Update readme
1 parent 2714424 commit df2f6f6

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ RushDB Python SDK uses a modern `SearchResult` container that follows Python SDK
103103

104104
### SearchResult Features
105105

106+
- **Generic type support**: Uses Python's typing generics (`SearchResult[T]`) with `RecordSearchResult` as a type alias for `SearchResult[Record]`
106107
- **List-like access**: Index, slice, and iterate like a regular list
107108
- **Search context**: Access total count, pagination info, and the original search query
108-
- **Boolean conversion**: Use in if statements naturally
109+
- **Boolean conversion**: Use in if statements naturally (returns `True` if the result contains any items)
109110
- **Pagination support**: Built-in pagination information and `has_more` property
110111

111112
### Basic Usage
@@ -139,20 +140,49 @@ names = [r.get('name') for r in result]
139140
# Indexing and slicing
140141
first_record = result[0] if result else None
141142
first_five = result[:5]
143+
144+
# String representation
145+
print(repr(result)) # SearchResult(count=10, total=42)
146+
```
147+
148+
### SearchResult Constructor
149+
150+
```python
151+
def __init__(
152+
self,
153+
data: List[T],
154+
total: Optional[int] = None,
155+
search_query: Optional[SearchQuery] = None,
156+
):
157+
"""
158+
Initialize search result.
159+
160+
Args:
161+
data: List of result items
162+
total: Total number of matching records (defaults to len(data) if not provided)
163+
search_query: The search query used to generate this result (defaults to {})
164+
"""
142165
```
143166

144167
### SearchResult Properties
145168

146169
| Property | Type | Description |
147170
| -------------- | --------------- | ---------------------------------------- |
148-
| `data` | `List[Record]` | The list of record results |
171+
| `data` | `List[T]` | The list of result items (generic type) |
149172
| `total` | `int` | Total number of matching records |
150173
| `count` | `int` | Number of records in current result set |
151174
| `limit` | `Optional[int]` | Limit that was applied to the search |
152175
| `skip` | `int` | Number of records that were skipped |
153176
| `has_more` | `bool` | Whether there are more records available |
154177
| `search_query` | `SearchQuery` | The search query used to generate result |
155178

179+
> **Implementation Notes:**
180+
>
181+
> - If `search_query` is not provided during initialization, it defaults to an empty dictionary `{}`
182+
> - The `skip` property checks if `search_query` is a dictionary and returns the "skip" value or 0
183+
> - The `has_more` property is calculated as `total > (skip + len(data))`, allowing for efficient pagination
184+
> - The `__bool__` method returns `True` if the result contains any items (`len(data) > 0`)
185+
156186
### Pagination Example
157187

158188
```python
@@ -182,6 +212,17 @@ while True:
182212
current_page += 1
183213
```
184214

215+
### RecordSearchResult Type
216+
217+
The SDK provides a specialized type alias for search results containing Record objects:
218+
219+
```python
220+
# Type alias for record search results
221+
RecordSearchResult = SearchResult[Record]
222+
```
223+
224+
This type is what's returned by methods like `db.records.find()`, providing type safety and specialized handling for Record objects while leveraging all the functionality of the generic SearchResult class.
225+
185226
## Improved Record API
186227

187228
The Record class has been enhanced with better data access patterns and utility methods.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy