Skip to content

Commit

Permalink
fix pagination default 10 result by default
Browse files Browse the repository at this point in the history
limits the results to the offset and number of results given. Note that the offset is zero-indexed.
The default is 0 10, which returns 10 items starting from the first result.
You can use LIMIT 0 0 to count the number of documents in the result set without actually returning them.
  • Loading branch information
Marc Lemay committed Sep 2, 2024
1 parent 8a5dcf2 commit 0caf156
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Client/PredisClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public function keys(string $pattern): array
/**
* @inheritdoc
*/
public function search(string $prefixKey, array $search, array $orderBy, ?string $format = RedisFormat::HASH->value, ?int $numberOfResults = null, ?string $searchType = Property::INDEX_TAG): array
public function search(string $prefixKey, array $search, array $orderBy, ?string $format = RedisFormat::HASH->value, ?int $numberOfResults = null, int $offset = 0, ?string $searchType = Property::INDEX_TAG): array
{
$arguments = [RedisCommands::SEARCH->value, self::convertPrefix($prefixKey)];

Expand All @@ -306,6 +306,12 @@ public function search(string $prefixKey, array $search, array $orderBy, ?string
$arguments[] = $direction;
}

if ($numberOfResults !== null) {
$arguments[] = 'LIMIT';
$arguments[] = $offset;
$arguments[] = $numberOfResults;
}

try {
$result = call_user_func_array([$this->redis, 'executeRaw'], [$arguments]);
} catch (\RedisException $e) {
Expand Down
6 changes: 6 additions & 0 deletions src/Client/RedisClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ public function search(string $prefixKey, array $search, array $orderBy, ?string
$arguments[] = $numberOfResults;
}

if ($numberOfResults !== null) {
$arguments[] = 'LIMIT';
$arguments[] = $offset;
$arguments[] = $numberOfResults;
}

try {
$result = call_user_func_array([$this->redis, 'rawCommand'], $arguments);
} catch (\RedisException $e) {
Expand Down

0 comments on commit 0caf156

Please sign in to comment.