From 669095e907571984a183d4fc27174d816a1dceee Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Sun, 20 Dec 2020 00:35:57 +0300 Subject: [PATCH] Optimizing empty search query a bit. --- src/Search/TorrentSearcher.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Search/TorrentSearcher.php b/src/Search/TorrentSearcher.php index 484c58f..f05aeab 100644 --- a/src/Search/TorrentSearcher.php +++ b/src/Search/TorrentSearcher.php @@ -39,9 +39,15 @@ class TorrentSearcher { $qb = $this->torrentRepo->createQueryBuilder('t'); + $queryParts = $this->splitQueryToParts($query); + + if (count($queryParts) < 1) { + return $qb; + } + $where = $qb->expr()->andX(); - foreach ($this->splitQueryToParts($query) as $idx => $part) { + foreach ($queryParts as $idx => $part) { $where->add('ILIKE(t.name , :part_'.$idx.') = TRUE'); $qb->setParameter('part_'.$idx, '%'.strtolower($part).'%'); }