From 0a2778aa6642de539853ab4ecb7d566c0be05f2d Mon Sep 17 00:00:00 2001 From: Jim Mason Date: Wed, 18 Oct 2023 09:50:16 +0100 Subject: [PATCH] allow camelcase hashtags; show tags from more recent reviews last --- ui/Search.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ui/Search.php b/ui/Search.php index 303bf3a5..387e20f0 100644 --- a/ui/Search.php +++ b/ui/Search.php @@ -34,6 +34,8 @@ use ZK\UI\UICommon as UI; class Search extends MenuItem { + const HASHTAG_PALETTE_SIZE = 5; // css colours palette-0..palette-(n-1) + private static $legacySearchActions = [ [ "", "searchForm" ], [ "byAlbumKey", "searchByAlbumKey" ], @@ -128,14 +130,15 @@ public function searchByAlbumKey($key = null) { $this->addVar("reviews", $reviews); // hashtags - $hashtags = array_reduce($reviews, function($carry, $review) { + $hashtags = array_reduce(array_reverse($reviews), function($carry, $review) { return preg_match_all('/#[\pL_]+/', $review['review'], $matches) ? array_merge($carry, $matches[0]) : $carry; }, []); - $hashtags = array_unique(array_map('strtolower', $hashtags)); + $normalized = array_unique(array_map('strtolower', $hashtags)); + $hashtags = array_intersect_key($hashtags, $normalized); $index = array_map(function($tag) { - return hexdec(hash('crc32', $tag)) % 5; - }, $hashtags); + return hexdec(hash('crc32', $tag)) % self::HASHTAG_PALETTE_SIZE; + }, $normalized); $this->addVar("hashtags", array_combine($hashtags, $index)); // tracks