diff --git a/app/Enums/SearchType.php b/app/Enums/SearchType.php index 36607a2e5d..119a97c988 100644 --- a/app/Enums/SearchType.php +++ b/app/Enums/SearchType.php @@ -32,6 +32,8 @@ abstract class SearchType public const UserModerationComment = 12; + public const Hub = 13; + public static function cases(): array { // NOTE: this order determines the order of the items in the 'search in' dropdown @@ -50,6 +52,7 @@ public static function cases(): array self::GameHashComment, self::SetClaimComment, self::UserModerationComment, + self::Hub, ]; } @@ -74,6 +77,7 @@ public static function toString(int $type): string SearchType::UserModerationComment => "User Moderation Comments", SearchType::GameHashComment => "Game Hash Comments", SearchType::SetClaimComment => "Set Claim Comments", + SearchType::Hub => "Hubs", default => "Invalid search type", }; } diff --git a/app/Helpers/database/search.php b/app/Helpers/database/search.php index fd447a7501..5289feb319 100644 --- a/app/Helpers/database/search.php +++ b/app/Helpers/database/search.php @@ -3,6 +3,7 @@ use App\Community\Enums\ArticleType; use App\Enums\Permissions; use App\Enums\SearchType; +use App\Platform\Enums\GameSetType; function canSearch(int $searchType, int $permissions): bool { @@ -51,11 +52,30 @@ function performSearch( FROM GameData AS gd LEFT JOIN Achievements AS ach ON ach.GameID = gd.ID AND ach.Flags = 3 LEFT JOIN Console AS c ON gd.ConsoleID = c.ID - WHERE gd.Title LIKE '%$searchQuery%' + WHERE gd.ConsoleID != 100 + AND gd.Title LIKE '%$searchQuery%' GROUP BY gd.ID, gd.Title ORDER BY SecondarySort, REPLACE(gd.Title, '|', ''), gd.Title"; } + if (in_array(SearchType::Hub, $searchType)) { + $counts[] = "SELECT COUNT(*) AS Count FROM game_sets WHERE deleted_at IS NULL AND type = '" . GameSetType::Hub->value . "' AND title LIKE '%$searchQuery%'"; + $parts[] = " + SELECT " . SearchType::Hub . " AS Type, gs.id AS ID, CONCAT('/hub/', gs.id) AS Target, + CONCAT(gs.title, ' (Hub)') AS Title, + CASE + WHEN gs.title LIKE '$searchQuery%' THEN 0 + WHEN gs.title LIKE '%~ $searchQuery%' THEN 1 + ELSE 2 + END AS SecondarySort + FROM game_sets AS gs + WHERE gs.deleted_at IS NULL + AND gs.type = '" . GameSetType::Hub->value . "' + AND gs.title LIKE '%$searchQuery%' + GROUP BY gs.id, gs.title + ORDER BY SecondarySort, REPLACE(gs.title, '|', ''), gs.title"; + } + if (in_array(SearchType::Achievement, $searchType)) { $counts[] = "SELECT COUNT(*) AS Count FROM Achievements WHERE Title LIKE '%$searchQuery%'"; $parts[] = " diff --git a/public/request/search.php b/public/request/search.php index af2a7ac824..11eae34d32 100644 --- a/public/request/search.php +++ b/public/request/search.php @@ -25,7 +25,7 @@ } elseif ($source == 'user' || $source == 'game-compare') { $order = [SearchType::User]; } else { - $order = [SearchType::Game, SearchType::Achievement, SearchType::User]; + $order = [SearchType::Game, SearchType::Hub, SearchType::Achievement, SearchType::User]; } performSearch($order, $searchTerm, 0, $maxResults, $permissions, $results, wantTotalResults: false); diff --git a/resources/views/pages-legacy/searchresults.blade.php b/resources/views/pages-legacy/searchresults.blade.php index eedf2929c5..702fd4fe5e 100644 --- a/resources/views/pages-legacy/searchresults.blade.php +++ b/resources/views/pages-legacy/searchresults.blade.php @@ -4,6 +4,7 @@ use App\Enums\SearchType; use App\Models\Achievement; +use App\Models\GameSet; authenticateFromCookie($user, $permissions, $userDetails); @@ -112,6 +113,21 @@ echo ""; break; + case SearchType::Hub: + echo "