Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(search): add support for modern hubs #3190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/Enums/SearchType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,6 +52,7 @@ public static function cases(): array
self::GameHashComment,
self::SetClaimComment,
self::UserModerationComment,
self::Hub,
];
}

Expand All @@ -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",
};
}
Expand Down
22 changes: 21 additions & 1 deletion app/Helpers/database/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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[] = "
Expand Down
2 changes: 1 addition & 1 deletion public/request/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions resources/views/pages-legacy/searchresults.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Enums\SearchType;
use App\Models\Achievement;
use App\Models\GameSet;

authenticateFromCookie($user, $permissions, $userDetails);

Expand Down Expand Up @@ -112,6 +113,21 @@
echo "</td>";
break;

case SearchType::Hub:
echo "<td>Hub</td>";
$hub = GameSet::find($nextID);
echo "<td colspan='2'>";
echo gameAvatar(
[
'GameID' => $hub->game_id,
'ImageIcon' => $hub->image_asset_path
],
title: $hub->title,
href: route('hub.show', $hub)
);
echo "</td>";
break;

case SearchType::Forum:
echo "<td>Forum Comment</td>";
echo "<td>";
Expand Down