Skip to content

Commit

Permalink
allow camelcase hashtags; show tags from more recent reviews last
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketMan committed Oct 18, 2023
1 parent 7d7f67f commit 0a2778a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ui/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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" ],
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0a2778a

Please sign in to comment.