]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Repository/EntryRepository.php
Added a simple search engine
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / EntryRepository.php
index 61be5220149771143f573aa27127fb461b9f9a6f..8f23164f7458c67efacc21da1808831d879f197c 100644 (file)
@@ -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.
      *