From 6342c9a87509fddb3b3ec9046b111bdc2090bc00 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Thu, 22 Jul 2021 19:05:55 +0200 Subject: Add LIMIT and OFFSET parameters for search method --- core/namespace/ORM/Repository.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/namespace/ORM/Repository.php b/core/namespace/ORM/Repository.php index a1efa3c..b2778f4 100644 --- a/core/namespace/ORM/Repository.php +++ b/core/namespace/ORM/Repository.php @@ -261,7 +261,7 @@ abstract class Repository { #=============================================================================== # Get entities based on search query #=============================================================================== - public function search(string $search, array $filter = []): array { + public function search(string $search, array $filter = [], int $limit = NULL, int $offset = 0): array { if($search === '*') { return $this->getAll([], NULL, 20); } @@ -281,11 +281,15 @@ abstract class Repository { $params[] = $filter['day']; } + if($limit) { + $limit = "LIMIT $offset,$limit"; + } + $dateparts = implode(' ', $extend ?? []); $query = 'SELECT * FROM %s WHERE %s MATCH(name, body) - AGAINST(? IN BOOLEAN MODE) LIMIT 20'; - $query = sprintf($query, static::getTableName(), $dateparts); + AGAINST(? IN BOOLEAN MODE) %s'; + $query = sprintf($query, static::getTableName(), $dateparts, $limit ?? 'LIMIT 20'); $Statement = $this->Database->prepare($query); $Statement->execute(array_merge($params ?? [], [$search])); -- cgit v1.2.3