aboutsummaryrefslogtreecommitdiff
path: root/src/Search/TagExpr.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Search/TagExpr.php')
-rw-r--r--src/Search/TagExpr.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/Search/TagExpr.php b/src/Search/TagExpr.php
new file mode 100644
index 0000000..b117bbe
--- /dev/null
+++ b/src/Search/TagExpr.php
@@ -0,0 +1,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;
+ }
+} \ No newline at end of file