From 8ff913aaf239bcacc5f8b0a8b7e0f6f062d4e26e Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 2 Feb 2020 20:07:19 +0100 Subject: [PATCH] Ensured search terms are applied to the domain too --- module/Core/src/Repository/ShortUrlRepository.php | 14 ++++++++------ module/Rest/test-api/Action/ListShortUrlsTest.php | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/module/Core/src/Repository/ShortUrlRepository.php b/module/Core/src/Repository/ShortUrlRepository.php index a9d21952..31fe1385 100644 --- a/module/Core/src/Repository/ShortUrlRepository.php +++ b/module/Core/src/Repository/ShortUrlRepository.php @@ -110,12 +110,14 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI } // Apply search conditions - $qb->andWhere($qb->expr()->orX( - $qb->expr()->like('s.longUrl', ':searchPattern'), - $qb->expr()->like('s.shortCode', ':searchPattern'), - $qb->expr()->like('t.name', ':searchPattern'), - )); - $qb->setParameter('searchPattern', '%' . $searchTerm . '%'); + $qb->leftJoin('s.domain', 'd') + ->andWhere($qb->expr()->orX( + $qb->expr()->like('s.longUrl', ':searchPattern'), + $qb->expr()->like('s.shortCode', ':searchPattern'), + $qb->expr()->like('t.name', ':searchPattern'), + $qb->expr()->like('d.authority', ':searchPattern'), + )) + ->setParameter('searchPattern', '%' . $searchTerm . '%'); } // Filter by tags if provided diff --git a/module/Rest/test-api/Action/ListShortUrlsTest.php b/module/Rest/test-api/Action/ListShortUrlsTest.php index 7af30948..7d4e51a7 100644 --- a/module/Rest/test-api/Action/ListShortUrlsTest.php +++ b/module/Rest/test-api/Action/ListShortUrlsTest.php @@ -169,6 +169,9 @@ class ListShortUrlsTest extends ApiTestCase self::SHORT_URL_META, self::SHORT_URL_CUSTOM_DOMAIN, ]]; + yield [['searchTerm' => 'example.com'], [ + self::SHORT_URL_CUSTOM_DOMAIN, + ]]; } private function buildPagination(int $itemsCount): array