aboutsummaryrefslogtreecommitdiff
path: root/src/Search/TagExpr.php
blob: b117bbe51dfa025359b3380b6fd894efa3834ae0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php


namespace Micropoly\Search;


class TagExpr implements SearchExpr
{
    private string $tag;

    public function __construct(string $tag)
    {
        $this->tag = $tag;
    }

    public function getTag(): string { return $this->tag; }

    public function toString(): string
    {
        return "#{$this->tag}";
    }

    public function toSQL(string $bindPrefix, bool $singleFTS): SQLSearchExpr
    {
        $sqlex = new SQLSearchExpr();

        $sqlex->sql = "EXISTS (
            SELECT 1
            FROM tags t
            WHERE t.tag = :{$bindPrefix}tag
                AND t.note_id = n.id
        )";
        $sqlex->bindings["{$bindPrefix}tag"] = $this->tag;

        return $sqlex;
    }

    public function countFTSQueries(): int
    {
        return 0;
    }
}