Optimizing empty search query a bit.

This commit is contained in:
Alexey Skobkin 2020-12-20 00:35:57 +03:00
parent d4479189d3
commit 669095e907
No known key found for this signature in database
GPG key ID: 5D5CEF6F221278E7

View file

@ -39,9 +39,15 @@ class TorrentSearcher
{ {
$qb = $this->torrentRepo->createQueryBuilder('t'); $qb = $this->torrentRepo->createQueryBuilder('t');
$queryParts = $this->splitQueryToParts($query);
if (count($queryParts) < 1) {
return $qb;
}
$where = $qb->expr()->andX(); $where = $qb->expr()->andX();
foreach ($this->splitQueryToParts($query) as $idx => $part) { foreach ($queryParts as $idx => $part) {
$where->add('ILIKE(t.name , :part_'.$idx.') = TRUE'); $where->add('ILIKE(t.name , :part_'.$idx.') = TRUE');
$qb->setParameter('part_'.$idx, '%'.strtolower($part).'%'); $qb->setParameter('part_'.$idx, '%'.strtolower($part).'%');
} }