-
Notifications
You must be signed in to change notification settings - Fork 122
Open
Description
Summary
The current FindQuery.count() implementation uses FT.SEARCH with LIMIT 0 0 and nocontent=True:
async def count(self):
query = self.copy(offset=0, limit=0, nocontent=True)
result = await query.execute(exhaust_results=True, return_raw_result=True)
return result[0]This works, but FT.AGGREGATE with a count reducer may be a better approach.
Why FT.AGGREGATE might be better
- Purpose-built for aggregations -
FT.AGGREGATEis designed for operations like counting, grouping, etc. - More flexible - Could support
count()with grouping (e.g., count by category) - Potentially more efficient - Aggregation pipeline is optimized for this use case
Example with FT.AGGREGATE
FT.AGGREGATE idx * GROUPBY 0 REDUCE COUNT 0 AS total
This returns just the count without any document data.
Tasks
- Benchmark current
FT.SEARCH LIMIT 0 0vsFT.AGGREGATEfor count - Evaluate if
FT.AGGREGATEprovides any performance benefits - Consider adding grouped count support (e.g.,
Model.find().count(group_by="category"))
Metadata
Metadata
Assignees
Labels
No labels