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

Include user tags in Beatmapset search #11763

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
index tags per beatmap instead
  • Loading branch information
notbakaneko committed Jan 15, 2025
commit 63b6663919c43012dcb9b0dbfb5797c98248b6b4
51 changes: 24 additions & 27 deletions app/Models/Traits/Es/BeatmapsetSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use App\Models\Beatmap;
use Carbon\Carbon;
use Ds\Set;

trait BeatmapsetSearch
{
Expand Down Expand Up @@ -58,7 +57,6 @@ private function esBeatmapsetValues()

$value = match ($field) {
'id' => $this->getKey(),
'tags' => $this->esTags(),
default => $this->$field,
};

Expand All @@ -80,12 +78,17 @@ private function esBeatmapsValues()
foreach ($this->beatmaps as $beatmap) {
$beatmapValues = [];
foreach ($mappings as $field => $mapping) {
$beatmapValues[$field] = $beatmap->$field;
$value = match ($field) {
'top_tags' => $this->esBeatmapTags($beatmap),
// TODO: remove adding $beatmap->user_id once everything else also populated beatmap_owners by default.
// Duplicate user_id in the array should be fine for now since the field isn't scored for querying.
'user_id' => $beatmap->beatmapOwners->pluck('user_id')->add($beatmap->user_id),
default => $beatmap->$field,
};

$beatmapValues[$field] = $value;
}

// TODO: remove adding $beatmap->user_id once everything else also populated beatmap_owners by default.
// Duplicate user_id in the array should be fine for now since the field isn't scored for querying.
$beatmapValues['user_id'] = $beatmap->beatmapOwners->pluck('user_id')->add($beatmap->user_id);
$values[] = $beatmapValues;

if ($beatmap->playmode === Beatmap::MODES['osu']) {
Expand All @@ -94,15 +97,10 @@ private function esBeatmapsValues()
continue;
}

$convert = clone $beatmap;
$convert->playmode = $modeInt;
$convert->convert = true;
$convertValues = [];
foreach ($mappings as $field => $mapping) {
$convertValues[$field] = $convert->$field;
}
$convertValues = $beatmapValues;
$convertValues['playmode'] = $modeInt;
$convertValues['convert'] = true;

$convertValues['user_id'] = $beatmapValues['user_id']; // just add a copy for converts too.
$values[] = $convertValues;
}
}
Expand All @@ -111,6 +109,18 @@ private function esBeatmapsValues()
return $values;
}

private function esBeatmapTags(Beatmap $beatmap): array
{
$tags = app('tags');

return array_filter(
array_map(
fn ($tagId) => $tags->get($tagId['tag_id'])?->name,
$beatmap->topTagIds()
)
);
}

private function esDifficultiesValues()
{
$mappings = static::esMappings()['difficulties']['properties'];
Expand All @@ -129,17 +139,4 @@ private function esDifficultiesValues()

return $values;
}

private function esTags()
{
$tags = app('tags');
$tagSet = new Set([$this->tags]);
$beatmapTagNames = $this->beatmaps
->flatMap(fn (Beatmap $beatmap) => $beatmap->topTagIds())
->map(fn ($tagId) => $tags->get($tagId['tag_id'])?->name);

$tagSet->add(...$beatmapTagNames->filter());

return $tagSet->toArray();
}
}
3 changes: 3 additions & 0 deletions config/schemas/beatmapsets.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
"playmode": {
"type": "byte"
},
"top_tags": {
"type": "text"
},
"total_length": {
"type": "long"
},
Expand Down