From ee122a7528f55dfb5f02e351c509d00b756fedaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 4 Nov 2016 23:24:43 +0100 Subject: Added a simple search engine Fix #18 --- .../CoreBundle/Repository/EntryRepository.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/Wallabag/CoreBundle/Repository') diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 61be5220..8f23164f 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -85,6 +85,25 @@ class EntryRepository extends EntityRepository ; } + /** + * Retrieves entries filtered with a search term for a user. + * + * @param int $userId + * @param string $term + * + * @return QueryBuilder + */ + public function getBuilderForSearchByUser($userId, $term) + { + return $this + ->getBuilderByUser($userId) + ->andWhere('e.content LIKE :term')->setParameter('term', '%'.$term.'%') + ->orWhere('e.title LIKE :term')->setParameter('term', '%'.$term.'%') + ->leftJoin('e.tags', 't') + ->groupBy('e.id') + ->having('count(t.id) = 0'); + } + /** * Retrieves untagged entries for a user. * -- cgit v1.2.3 From 49b042dfdf33a0efd3c838e1476754e6019730d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 10 Nov 2016 15:23:53 +0100 Subject: Added translations and currentRoute parameter --- .../CoreBundle/Repository/EntryRepository.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/Wallabag/CoreBundle/Repository') diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 8f23164f..51cfe4d1 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -90,18 +90,30 @@ class EntryRepository extends EntityRepository * * @param int $userId * @param string $term + * @param strint $currentRoute * * @return QueryBuilder */ - public function getBuilderForSearchByUser($userId, $term) + public function getBuilderForSearchByUser($userId, $term, $currentRoute) { - return $this - ->getBuilderByUser($userId) - ->andWhere('e.content LIKE :term')->setParameter('term', '%'.$term.'%') - ->orWhere('e.title LIKE :term')->setParameter('term', '%'.$term.'%') + $qb = $this + ->getBuilderByUser($userId); + + if ('starred' === $currentRoute) { + $qb->andWhere('e.isStarred = true'); + } elseif ('unread' === $currentRoute) { + $qb->andWhere('e.isArchived = false'); + } elseif ('archive' === $currentRoute) { + $qb->andWhere('e.isArchived = true'); + } + + $qb + ->andWhere('e.content LIKE :term OR e.title LIKE :term')->setParameter('term', '%'.$term.'%') ->leftJoin('e.tags', 't') ->groupBy('e.id') ->having('count(t.id) = 0'); + + return $qb; } /** -- cgit v1.2.3 From 32f455c1317bf536aea63147d2c5074ae7425d42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 18 Nov 2016 17:36:19 +0100 Subject: Added tests --- src/Wallabag/CoreBundle/Repository/EntryRepository.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/Wallabag/CoreBundle/Repository') diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 51cfe4d1..47e24d6b 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -110,8 +110,7 @@ class EntryRepository extends EntityRepository $qb ->andWhere('e.content LIKE :term OR e.title LIKE :term')->setParameter('term', '%'.$term.'%') ->leftJoin('e.tags', 't') - ->groupBy('e.id') - ->having('count(t.id) = 0'); + ->groupBy('e.id'); return $qb; } -- cgit v1.2.3