aboutsummaryrefslogtreecommitdiff
path: root/src/Search/AbstractFTSExpr.php
blob: b72b1b6ef12d0120e30860cc66104e1016b76f76 (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
<?php


namespace Micropoly\Search;


abstract class AbstractFTSExpr implements SearchExpr
{
    abstract protected function fts4Query(): string;

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

        $sqlex->sql = $singleFTS
            ? "nc.note_contents MATCH :{$bindPrefix}match"
            : "n.content_row IN (
                SELECT rowid
                FROM note_contents
                WHERE note_contents MATCH :{$bindPrefix}match
            )";
        $sqlex->bindings["{$bindPrefix}match"] = $this->fts4Query();

        return $sqlex;
    }

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