aboutsummaryrefslogtreecommitdiff
path: root/src/Handlers/Search.php
diff options
context:
space:
mode:
authorLaria Carolin Chabowski <laria@laria.me>2020-02-07 09:44:59 +0100
committerLaria Carolin Chabowski <laria@laria.me>2020-02-07 09:44:59 +0100
commit2eb5a432d2229788ce2fdb09f36c6f4bebdea813 (patch)
treeab57978bdda34c82b025b897cfb6825b1fd1e654 /src/Handlers/Search.php
downloadmicropoly-2eb5a432d2229788ce2fdb09f36c6f4bebdea813.tar.gz
micropoly-2eb5a432d2229788ce2fdb09f36c6f4bebdea813.tar.bz2
micropoly-2eb5a432d2229788ce2fdb09f36c6f4bebdea813.zip
Initial commit
Diffstat (limited to 'src/Handlers/Search.php')
-rw-r--r--src/Handlers/Search.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/Handlers/Search.php b/src/Handlers/Search.php
new file mode 100644
index 0000000..30311ea
--- /dev/null
+++ b/src/Handlers/Search.php
@@ -0,0 +1,33 @@
+<?php
+
+
+namespace Micropoly\Handlers;
+
+use Micropoly\Env;
+use Micropoly\Handler;
+use Micropoly\Models\Note;
+use Micropoly\Search\ParseError;
+use Micropoly\Search\Parser;
+use Micropoly\Search\SearchResult;
+use Micropoly\Search\TrueExpr;
+
+class Search implements Handler
+{
+ public function handle(Env $env, array $variables)
+ {
+ $vars = ["query" => $_GET["q"] ?? ""];
+
+ try {
+ $expr = isset($_GET["q"])
+ ? (Parser::parse($_GET["q"]) ?? new TrueExpr())
+ : new TrueExpr();
+
+ $results = SearchResult::search($env->db(), $expr);
+ $vars["results"] = $results;
+ } catch (ParseError $e) {
+ $vars["error"] = $e->getMessage();
+ }
+
+ echo $env->twig()->render("/search.twig", $vars);
+ }
+} \ No newline at end of file