From 8308ab28f9397616036d2281d4483a16cdde2bfd Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 15 Oct 2023 06:37:22 +0300 Subject: [PATCH] order keywords by quantity matches in content --- src/Controller/TorrentController.php | 32 +++++++++++++++++++----- templates/default/torrent/list.html.twig | 6 ++--- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/Controller/TorrentController.php b/src/Controller/TorrentController.php index cc6bb6a..078bad9 100644 --- a/src/Controller/TorrentController.php +++ b/src/Controller/TorrentController.php @@ -262,16 +262,26 @@ class TorrentController extends AbstractController // Generate keywords by extension $keywords = []; + foreach ($file->getFileList() as $item) { if ($keyword = pathinfo($item['path'], PATHINFO_EXTENSION)) { - $keywords[] = mb_strtolower($keyword); + $keyword = mb_strtolower($keyword); + + if (isset($keywords[$keyword])) + { + $keywords[$keyword]++; + } + + else + { + $keywords[$keyword] = 1; + } } } - $keywords = array_unique($keywords); - sort($keywords); + arsort($keywords); // Push torrent $torrents[] = @@ -401,16 +411,26 @@ class TorrentController extends AbstractController // Generate keywords by extension $keywords = []; + foreach ($file->getFileList() as $item) { if ($keyword = pathinfo($item['path'], PATHINFO_EXTENSION)) { - $keywords[] = mb_strtolower($keyword); + $keyword = mb_strtolower($keyword); + + if (isset($keywords[$keyword])) + { + $keywords[$keyword]++; + } + + else + { + $keywords[$keyword] = 1; + } } } - $keywords = array_unique($keywords); - sort($keywords); + arsort($keywords); // Push torrent $torrents[] = diff --git a/templates/default/torrent/list.html.twig b/templates/default/torrent/list.html.twig index 27dcb2b..8c3b35e 100644 --- a/templates/default/torrent/list.html.twig +++ b/templates/default/torrent/list.html.twig @@ -13,7 +13,7 @@ {% if torrents %} {% for torrent in torrents %} -
+

@@ -44,8 +44,8 @@

{% if torrent.keywords %}
- {% for keyword in torrent.keywords %} - + {% for keyword, quantity in torrent.keywords %} + #{{ keyword }} {% endfor %}