Skip to content

Commit

Permalink
Merge pull request #77 from flug/add/offset-find-method
Browse files Browse the repository at this point in the history
add offset to find* methods
  • Loading branch information
clementtalleu authored Sep 2, 2024
2 parents e548a5c + 735bf82 commit f8961cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/Om/Repository/AbstractObjectRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@ abstract public function getPropertyValue($identifier, string $property): mixed;
/**
* @inheritdoc
*/
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = 0): array
{
$this->convertDates($criteria);
$this->convertSpecial($criteria);
$data = $this->redisClient->search($this->prefix, $criteria, $orderBy ?? [], $this->format, $limit);
$data = $this->redisClient->search(
$this->prefix,
$criteria,
$orderBy ?? [],
$this->format,
$limit,
offset: $offset
);

$collection = [];
foreach ($data as $item) {
Expand All @@ -52,7 +59,7 @@ public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = nu
/**
* @inheritdoc
*/
public function findByLike(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
public function findByLike(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = 0): array
{
$this->convertDates($criteria);
$this->convertSpecial($criteria);
Expand All @@ -61,7 +68,7 @@ public function findByLike(array $criteria, ?array $orderBy = null, ?int $limit
unset($criteria[$property]);
}

$data = $this->redisClient->search(prefixKey: $this->prefix, search: $criteria, orderBy: $orderBy ?? [], format: $this->format, numberOfResults: $limit, searchType: Property::INDEX_TEXT);
$data = $this->redisClient->search(prefixKey: $this->prefix, search: $criteria, orderBy: $orderBy ?? [], format: $this->format, numberOfResults: $limit, offset: $offset, searchType: Property::INDEX_TEXT);

$collection = [];
foreach ($data as $item) {
Expand Down
2 changes: 1 addition & 1 deletion src/Om/Repository/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = nu
* @param array $criteria as ['property' => 'val'] should return objects where property contains val/value/orval...
* @param array|null $orderBy as ['property' => 'ASC|DESC']
*/
public function findByLike(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array;
public function findByLike(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = 0): array;

/**
* Find objects by a full text search.
Expand Down

0 comments on commit f8961cc

Please sign in to comment.