From 99b08879bd918bf3c158a21bd14199f3b313c175 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 10 Oct 2014 20:05:32 +0200 Subject: [PATCH] Improved search speed --- src/Dao/PostDao.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Dao/PostDao.php b/src/Dao/PostDao.php index 4d6dbfb5..3723bdf0 100644 --- a/src/Dao/PostDao.php +++ b/src/Dao/PostDao.php @@ -118,16 +118,20 @@ class PostDao extends AbstractDao implements ICrudDao { if ($requirement->getType() === PostFilter::REQUIREMENT_TAG) { + $tagName = $requirement->getValue()->getValue(); + $tag = $this->tagDao->findByName($tagName); + if (!$tag) + throw new \DomainException('Invalid tag: "' . $tagName . '"'); + $sql = 'EXISTS ( SELECT 1 FROM postTags - INNER JOIN tags ON postTags.tagId = tags.id WHERE postTags.postId = posts.id - AND LOWER(tags.name) = LOWER(?))'; + AND postTags.tagId = ?)'; if ($requirement->isNegated()) $sql = 'NOT ' . $sql; - $query->where($sql, $requirement->getValue()->getValue()); + $query->where($sql, $tag->getId()); return; }