Skip to content

Commit a14c2aa

Browse files
committed
[index] support posted=<day>, fixes #782, fixes #783
1 parent cc32c94 commit a14c2aa

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

ext/index/main.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,20 @@ public function onSearchTermParse(SearchTermParseEvent $event): void
191191
} elseif ($matches = $event->matches("/^(filename|name)[=|:](.+)$/i")) {
192192
$filename = strtolower($matches[2]);
193193
$event->add_querylet(new Querylet("lower(images.filename) LIKE :filename{$event->id}", ["filename{$event->id}" => "%$filename%"]));
194-
} elseif ($matches = $event->matches("/^posted([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])([0-9-]*)$/i")) {
195-
// TODO Make this able to search = without needing a time component.
194+
} elseif ($matches = $event->matches("/^posted([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])([0-9]{4}[-\/][0-9]{2}[-\/][0-9]{2})$/i")) {
196195
$cmp = ltrim($matches[1], ":") ?: "=";
197-
$val = $matches[2];
198-
$event->add_querylet(new Querylet("images.posted $cmp :posted{$event->id}", ["posted{$event->id}" => $val]));
196+
$dt = new \Safe\DateTimeImmutable($matches[2]);
197+
if ($cmp === "=") {
198+
$event->add_querylet(new Querylet(
199+
"images.posted >= :posted{$event->id}_1 AND images.posted < :posted{$event->id}_2",
200+
["posted{$event->id}_1" => $dt->format('Y-m-d'), "posted{$event->id}_2" => $dt->modify('+1 day')->format('Y-m-d')]
201+
));
202+
} else {
203+
$event->add_querylet(new Querylet(
204+
"images.posted $cmp :posted{$event->id}",
205+
["posted{$event->id}" => $dt->format('Y-m-d')]
206+
));
207+
}
199208
} elseif ($matches = $event->matches("/^order[=|:](id|width|height|length|filesize|filename)[_]?(desc|asc)?$/i")) {
200209
$ord = strtolower($matches[1]);
201210
$default_order_for_column = \Safe\preg_match("/^(id|filename)$/", $matches[1]) ? "ASC" : "DESC";

0 commit comments

Comments
 (0)