aboutsummaryrefslogtreecommitdiff
path: root/src/Search/FTSLogicOp.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Search/FTSLogicOp.php')
-rw-r--r--src/Search/FTSLogicOp.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/Search/FTSLogicOp.php b/src/Search/FTSLogicOp.php
new file mode 100644
index 0000000..452f63b
--- /dev/null
+++ b/src/Search/FTSLogicOp.php
@@ -0,0 +1,46 @@
+<?php
+
+
+namespace Micropoly\Search;
+
+
+class FTSLogicOp extends AbstractFTSExpr
+{
+ private string $op;
+ private AbstractFTSExpr $a;
+ private AbstractFTSExpr $b;
+
+ /**
+ * FTSLogicOp constructor.
+ * @param string $op
+ * @param AbstractFTSExpr $a
+ * @param AbstractFTSExpr $b
+ */
+ public function __construct(string $op, AbstractFTSExpr $a, AbstractFTSExpr $b)
+ {
+ if (!LogicOp::checkOp($op))
+ throw new \DomainException("{$op} is not a valid operator");
+
+ $this->op = $op;
+ $this->a = $a;
+ $this->b = $b;
+ }
+
+ private const FTSOPS = [
+ LogicOp::OP_AND => "",
+ LogicOp::OP_OR => "OR",
+ ];
+
+ protected function fts4Query(): string
+ {
+ $ftsop = self::FTSOPS[$this->op];
+ assert($ftsop);
+
+ return "({$this->a->fts4Query()} {$ftsop} {$this->b->fts4Query()})";
+ }
+
+ public function toString(): string
+ {
+ return "({$this->a->toString()} FTS-{$this->op} {$this->b->toString()})";
+ }
+} \ No newline at end of file