diff --git a/lib/MusicBrainz/Server/Controller/Search.pm b/lib/MusicBrainz/Server/Controller/Search.pm index 3b474eca80c..86cd3a78615 100644 --- a/lib/MusicBrainz/Server/Controller/Search.pm +++ b/lib/MusicBrainz/Server/Controller/Search.pm @@ -188,6 +188,7 @@ sub direct : Private when ('series') { $c->model('SeriesType')->load(@entities); $c->model('SeriesOrderingType')->load(@entities); + $c->model('Series')->load_entity_count(@entities); } when ('event') { $c->model('Event')->load_related_info(@entities); diff --git a/lib/MusicBrainz/Server/Data/Search.pm b/lib/MusicBrainz/Server/Data/Search.pm index 21f08387df9..fac43937285 100644 --- a/lib/MusicBrainz/Server/Data/Search.pm +++ b/lib/MusicBrainz/Server/Data/Search.pm @@ -396,13 +396,29 @@ my %mapping = ( 'title' => 'name', 'artist-credit' => 'artist_credit', 'label-code' => 'label_code', + 'type-id' => 'type_id', ); sub schema_fixup_type { my ($self, $data, $type) = @_; + + my $type_gid = delete $data->{type_id}; + if (defined $data->{type} && $type ~~ [ entities_with(['type', 'simple']) ]) { + my $item_entity_type; + if ($type eq 'series') { + # This is needed to query the number of entities later + $item_entity_type = $self->c->sql->select_single_value( + 'SELECT entity_type FROM series_type WHERE gid = ?', + $type_gid + ); + } my $model = 'MusicBrainz::Server::Entity::' . type_to_model($type) . 'Type'; - $data->{type} = $model->new( name => $data->{type} ); + $data->{type} = $model->new( + name => $data->{type}, + gid => $type_gid, + defined $item_entity_type ? (item_entity_type => $item_entity_type) : (), + ); } return $data; } @@ -955,6 +971,13 @@ sub external_search $self->c->model('Artwork')->load_for_release_groups(@entities); } + if ($type eq 'series') + { + my @entities = map { $_->entity } @results; + $self->c->model('Series')->load_ids(@entities); + $self->c->model('Series')->load_entity_count(@entities); + } + my $pager = Data::Page->new; $pager->current_page($page); $pager->entries_per_page($limit); diff --git a/lib/MusicBrainz/Server/Data/Series.pm b/lib/MusicBrainz/Server/Data/Series.pm index 1524623aace..94e0c07ede8 100644 --- a/lib/MusicBrainz/Server/Data/Series.pm +++ b/lib/MusicBrainz/Server/Data/Series.pm @@ -12,6 +12,7 @@ use MusicBrainz::Server::Data::Utils qw( merge_table_attributes load_subobjects order_by + placeholders ); use MusicBrainz::Server::Data::Utils::Cleanup qw( used_in_relationship ); use MusicBrainz::Server::Data::Utils::Uniqueness qw( assert_uniqueness_conserved ); @@ -122,6 +123,31 @@ sub _merge_impl { return 1; } +=method load_ids + +Load internal IDs for event objects that only have GIDs. + +=cut + +sub load_ids +{ + my ($self, @series) = @_; + + my @gids = map { $_->gid } @series; + return () unless @gids; + + my $query = ' + SELECT gid, id FROM series + WHERE gid IN (' . placeholders(@gids) . ') + '; + my %map = map { $_->[0] => $_->[1] } + @{ $self->sql->select_list_of_lists($query, @gids) }; + + for my $series (@series) { + $series->id($map{$series->gid}) if exists $map{$series->gid}; + } +} + sub load { my ($self, @objs) = @_; diff --git a/root/search/components/SeriesResults.js b/root/search/components/SeriesResults.js index c2ecd17060a..1bda0cfb4a0 100644 --- a/root/search/components/SeriesResults.js +++ b/root/search/components/SeriesResults.js @@ -36,6 +36,9 @@ function buildResult( ? lp_attributes(series.typeName, 'series_type') : null} + + {series.entity_count} + ); } @@ -56,6 +59,7 @@ const SeriesResults = ({ <> {l('Name')} {l('Type')} + {l('Number of entities')} } pager={pager} diff --git a/t/lib/t/MusicBrainz/Server/Controller/Search/Indexed.pm b/t/lib/t/MusicBrainz/Server/Controller/Search/Indexed.pm index a20cc297361..4ace15077a9 100644 --- a/t/lib/t/MusicBrainz/Server/Controller/Search/Indexed.pm +++ b/t/lib/t/MusicBrainz/Server/Controller/Search/Indexed.pm @@ -25,6 +25,7 @@ test all => sub { { "id": "e414a176-b978-492f-b6bc-9fd4c89df221", "type": "Group", + "type-id": "e431f5f6-b5d2-343d-8b36-72607fffb74b", "score": "97", "name": "L.O.V.E.", "sort-name": "L.O.V.E.", @@ -61,6 +62,7 @@ test all => sub { { "id": "53299fed-ec27-464f-94eb-5fda2db2902a", "type": "Person", + "type-id": "b6e035f4-3ce9-331c-97df-83397230b0df", "score": "65", "name": "Laura Love", "sort-name": "Love, Laura", diff --git a/t/lib/t/MusicBrainz/Server/Data/Search.pm b/t/lib/t/MusicBrainz/Server/Data/Search.pm index a61de6a8972..3e72df38cdd 100644 --- a/t/lib/t/MusicBrainz/Server/Data/Search.pm +++ b/t/lib/t/MusicBrainz/Server/Data/Search.pm @@ -24,6 +24,7 @@ our $artist_json = < sub { is($artist->comment, 'folk-rock/psychedelic band'); is($artist->gid, '34ec9a8d-c65b-48fd-bcdd-aad2f72fdb47'); is($artist->type->name, 'Group'); + is($artist->type->gid, 'e431f5f6-b5d2-343d-8b36-72607fffb74b'); # release_group search $data = load_data('release_group', $test->c, @@ -484,6 +486,7 @@ EOF { "id": "e24ca2f9-416e-42bd-a223-bed20fa409d0", "type": "Production", + "type-id": "a2426aab-2dd4-339c-b47d-b4923a241678", "score": "100", "name": "Love Records", "sort-name": "Love Records", @@ -523,6 +526,7 @@ EOF is($label->comment, 'Finnish label'); is($label->gid, 'e24ca2f9-416e-42bd-a223-bed20fa409d0'); is($label->type->name, 'Production'); + is($label->type->gid, 'a2426aab-2dd4-339c-b47d-b4923a241678'); # annotation search $data = load_data('annotation', $test->c,