From b1af6a43365589f46bed2b0534f2f3892514cf12 Mon Sep 17 00:00:00 2001 From: Alexandre Morignot <erdnaxeli@cervoi.se> Date: Sun, 25 Jan 2015 01:33:15 +0100 Subject: [PATCH] searches (!get) with tags *really* work --- lib/commands/get.pm | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/commands/get.pm b/lib/commands/get.pm index efd9cf5..eb46c7e 100644 --- a/lib/commands/get.pm +++ b/lib/commands/get.pm @@ -50,35 +50,37 @@ sub exec { $sth->execute($words[0]); } elsif (@tags) { - my $params = join ', ' => ('?') x @tags; + my @where; + + foreach my $tag (@tags) { + unshift @where, 'p.id in (select pt.id from playbot_tags pt where pt.tag = ?)'; + } + + my $where = join ' and ' => @where; if ($all) { $req = 'select id, sender, title, url, duration from playbot - natural join playbot_tags - where tag in ('.$params.')'; + where '.$where; $req .= ' and '.$words_sql if ($words_sql); $req .= ' group by id - having count(*) >= ? order by rand()'; $sth = $dbh->prepare($req); - $sth->execute(@tags, @words_param, scalar @tags); + $sth->execute(@tags, @words_param); } else { $req = 'select p.id, p.sender, p.title, p.url, duration from playbot p - natural join playbot_tags pt join playbot_chan pc on p.id = pc.content - where pt.tag in ('.$params.')'; + where '.$where; $req .= ' and '.$words_sql if ($words_sql); $req .= ' and pc.chan = ? group by p.id - having count(*) >= ? order by rand()'; $sth = $dbh->prepare($req); - $sth->execute(@tags, @words_param, $chan->[0], scalar @tags); + $sth->execute(@tags, @words_param, $chan->[0]); } } else { -- GitLab