Improved search speed

This commit is contained in:
Marcin Kurczewski 2014-10-10 20:05:32 +02:00
parent da6c4681fa
commit 99b08879bd

View file

@ -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;
}