word: apply subselection before shuffle
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 20 Oct 2020 20:36:23 +0000 (22:36 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 20 Oct 2020 20:49:11 +0000 (22:49 +0200)
word.plp

index 2c16a24a71282d5433c3327223ad76f190ad9c6a..050ad90f626ddb79390343a57ba4b29a9bcc3096 100644 (file)
--- a/word.plp
+++ b/word.plp
@@ -93,7 +93,18 @@ sub printimgs {
 
 say '<section class="gallery">';
 if (exists $get{q}) {
-       my @rows = map {@$_} values %{$table}; # flatten categories
+       my @rows;
+       if ($Request) {
+               my @query = $Request;
+               while (@query) {
+                       push @rows, grep { (split /:/)[1] <= $limit } @query;
+                       s/:.*// for @query;
+                       @query = map {$_ ? @{$_} : ()} @{$table}{@query};
+               }
+       }
+       else {
+               @rows = map {ref ? @$_ : $_} values %{$table}; # flatten categories
+       }
        @rows = sort { rand <=> .5 } @rows;
        $table = {};
        printimgs(@rows);