I tried your code and realized that you could get more topResults, but you have to offset them. Increasing the limit did not work. My code:
let types: [MusicCatalogSearchable.Type] = [
Song.self,
Artist.self,
MusicVideo.self,
Album.self,
Playlist.self,
Curator.self,
RadioShow.self
]
var request = MusicCatalogSearchRequest(term: "weeknd", types: types)
request.includeTopResults = true
var topResults: MusicItemCollection<MusicCatalogSearchResponse.TopResult> = []
for offset in stride(from: 0, through: 15, by: 3) {
request.offset = offset
let response = try await request.response()
topResults += response.topResults
}
print(topResults)
The response is:
MusicItemCollection<MusicCatalogSearchResponse.TopResult>(
items: [
TopResult.artist(Artist(id: "479756766", name: "The Weeknd")),
TopResult.playlist(Playlist(id: "pl.659f6a1cac0f4232ad19d1a2cfdc9fb8", name: "The Weeknd Essentials", curatorName: "Apple Music R&B")),
TopResult.song(Song(id: "1488408568", title: "Blinding Lights", artistName: "The Weeknd")),
TopResult.song(Song(id: "1440870397", title: "I Feel It Coming (feat. Daft Punk)", artistName: "The Weeknd")),
TopResult.album(Album(id: "1603171516", title: "Dawn FM", artistName: "The Weeknd")),
TopResult.playlist(Playlist(id: "pl.774f9bceb38e45ef8f9f18e389a12160", name: "The Weeknd Video Essentials", curatorName: "Apple Music R&B")),
TopResult.song(Song(id: "1499378613", title: "Save Your Tears", artistName: "The Weeknd")),
TopResult.album(Album(id: "1440826239", title: "Beauty Behind the Madness", artistName: "The Weeknd")),
TopResult.playlist(Playlist(id: "pl.18f95e87b4ad427dba02bc7a79d0a84f", name: "The Weeknd: Influences", curatorName: "Apple Music R&B")),
TopResult.song(Song(id: "1499378615", title: "After Hours", artistName: "The Weeknd")),
TopResult.musicVideo(MusicVideo(id: "1579734725", title: "Take My Breath", artistName: "The Weeknd")),
TopResult.song(Song(id: "1563812775", title: "Save Your Tears (Remix)", artistName: "The Weeknd & Ariana Grande")),
TopResult.album(Album(id: "1499385848", title: "After Hours", artistName: "The Weeknd")),
TopResult.musicVideo(MusicVideo(id: "1528431580", title: "Smile", artistName: "Juice WRLD & The Weeknd")),
TopResult.song(Song(id: "1440870378", title: "Reminder", artistName: "The Weeknd")),
TopResult.album(Album(id: "1440858094", title: "Beauty Behind the Madness", artistName: "The Weeknd"))
]
)
However, with many network calls, this defeats the purpose of topResults, which is meant to get the results for the given search term quickly. There may be a better way to fetch all the top results, and I am all ears to know it.