From 790cb0d7a96fe00b5e5f755a6430a41838404407 Mon Sep 17 00:00:00 2001 From: Daku Date: Thu, 16 Jan 2014 08:31:34 +0000 Subject: [PATCH] [.+]tags metatag for tag_categories This is nowhere as near as fast as I'd like. Need to find a better query. --- ext/tag_categories/main.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ext/tag_categories/main.php b/ext/tag_categories/main.php index 4a5dcffa..285a18e8 100644 --- a/ext/tag_categories/main.php +++ b/ext/tag_categories/main.php @@ -48,6 +48,30 @@ class TagCategories extends Extension { } } + public function onSearchTermParse(SearchTermParseEvent $event) { + $matches = array(); + + if(preg_match("/^(.+)tags([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])([0-9]+)$/", $event->term, $matches)) { + global $database; + $type = $matches[1]; + $cmp = ltrim($matches[2], ":") ?: "="; + $count = $matches[3]; + + $types = $database->get_col('SELECT category FROM image_tag_categories'); + if(in_array($type, $types)) { + $event->add_querylet(new Querylet("images.id IN ( + SELECT * FROM ( + SELECT it.image_id + FROM image_tags it + LEFT JOIN tags t ON it.tag_id = t.id + GROUP BY image_id + HAVING SUM(CASE WHEN t.tag LIKE '$type:%' THEN 1 ELSE 0 END) $cmp $count + ) AS subquery + )")); + } + } + } + public function getDict() { global $database;