RustyNova016/musicbrainz_rs_nova

Limit / Offset feature

Closed this issue · 3 comments

There is currently no possibility to search for more then 25 entries at the same time.
Please correct me if im wrong.

Example:

let songs: Vec<String> = musicbrainz_rs_nova::entity::release::Release::search(
        musicbrainz_rs_nova::entity::release::ReleaseSearchQuery::query_builder()
            .artist("Neelix")
            .build(),
    )
    .execute()
    .unwrap()
    .entities
    .into_iter()
    .map(|val| format!("{}", val.title))
    .collect();

    println!("{:#?}", songs);
    println!("Got {} songs.", songs.len());

This will always return 25 entries (which is the default limit by mb).
But there should be a possibility to set the limit to a number of 1-100 (inclusive) and also you should be able to set the offset (aka the "page number")

This could be done by adding offset() and limit() to the SearchQuery struct.
Code using this could look like this.

let songs: Vec<String> = musicbrainz_rs_nova::entity::release::Release::search(
        musicbrainz_rs_nova::entity::release::ReleaseSearchQuery::query_builder()
            .artist("Neelix")
            .build(),
    )
    .limit(10)
    .offset(3)
    .execute()
    .unwrap()
    .entities
    .into_iter()
    .map(|val| format!("{}", val.title))
    .collect();

    println!("{:#?}", songs);
    println!("Got {} songs.", songs.len());

This would show 10 entries of the 3rd page (release 21-30).

Doc:
https://musicbrainz.org/doc/MusicBrainz_API/Search

PS.: Maybe I will take a closer look to the repo and create a PR later :)

This would be a great thing to add. Although I haven't dug too much into searches yet, it should be a few copy pastes from the BrowseQuerry

I'll try working on it tomorrow wince I'm back from vacation

Done. I still need to do a few things before I release the new version, but it should come out soon

Thank you very much :)