Commit c15374da authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

IArtist: Allow artist albums to be searched

parent 8d7c2df2
......@@ -43,6 +43,8 @@ public:
* appeared on, even if they are not the main artist (or AlbumArtist)
*/
virtual Query<IAlbum> albums( const QueryParameters* params = nullptr ) const = 0;
virtual Query<IAlbum> searchAlbums( const std::string& pattern,
const QueryParameters* params = nullptr ) const = 0;
virtual Query<IMedia> media( const QueryParameters* params = nullptr ) const = 0;
virtual const std::string& artworkMrl() const = 0;
virtual const std::string& musicBrainzId() const = 0;
......
......@@ -514,6 +514,19 @@ Query<IAlbum> Album::search( MediaLibraryPtr ml, const std::string& pattern,
return make_query<Album, IAlbum>( ml, "*", std::move( req ), pattern );
}
Query<IAlbum> Album::searchFromArtist( MediaLibraryPtr ml, const std::string& pattern,
int64_t artistId, const QueryParameters* params )
{
std::string req = "FROM " + policy::AlbumTable::Name + " alb "
"WHERE id_album IN "
"(SELECT rowid FROM " + policy::AlbumTable::Name + "Fts WHERE " +
policy::AlbumTable::Name + "Fts MATCH '*' || ? || '*')"
"AND is_present != 0 "
"AND artist_id = ?";
req += orderBy( params );
return make_query<Album, IAlbum>( ml, "*", std::move( req ), pattern, artistId );
}
Query<IAlbum> Album::fromArtist( MediaLibraryPtr ml, int64_t artistId, const QueryParameters* params )
{
std::string req = "FROM " + policy::AlbumTable::Name + " alb "
......
......@@ -114,6 +114,8 @@ class Album : public IAlbum, public DatabaseHelpers<Album, policy::AlbumTable>
///
static Query<IAlbum> search( MediaLibraryPtr ml, const std::string& pattern,
const QueryParameters* params );
static Query<IAlbum> searchFromArtist( MediaLibraryPtr ml, const std::string& pattern,
int64_t artistId, const QueryParameters* params );
static Query<IAlbum> fromArtist( MediaLibraryPtr ml, int64_t artistId, const QueryParameters* params );
static Query<IAlbum> fromGenre( MediaLibraryPtr ml, int64_t genreId, const QueryParameters* params );
static Query<IAlbum> listAll( MediaLibraryPtr ml, const QueryParameters* params );
......
......@@ -93,6 +93,12 @@ Query<IAlbum> Artist::albums( const QueryParameters* params ) const
return Album::fromArtist( m_ml, m_id, params );
}
Query<IAlbum> Artist::searchAlbums( const std::string& pattern,
const QueryParameters* params ) const
{
return Album::searchFromArtist( m_ml, pattern, m_id, params );
}
Query<IMedia> Artist::media( const QueryParameters* params ) const
{
std::string req = "FROM " + policy::MediaTable::Name + " med ";
......
......@@ -56,6 +56,8 @@ public:
virtual const std::string& shortBio() const override;
bool setShortBio( const std::string& shortBio );
virtual Query<IAlbum> albums( const QueryParameters* params ) const override;
virtual Query<IAlbum> searchAlbums( const std::string& pattern,
const QueryParameters* params = nullptr ) const override;
virtual Query<IMedia> media( const QueryParameters* params ) const override;
bool addMedia( Media& media );
virtual const std::string& artworkMrl() const override;
......
......@@ -547,3 +547,18 @@ TEST_F( Artists, Query )
artists = query->all();
ASSERT_EQ( 2u, artists.size() );
}
TEST_F( Artists, SearchAlbums )
{
auto artist = ml->createArtist( "artist" );
auto alb1 = ml->createAlbum( "album" );
alb1->setAlbumArtist( artist );
auto alb2 = ml->createAlbum( "other album" );
auto allAlbums = ml->searchAlbums( "album", nullptr )->all();
ASSERT_EQ( 2u, allAlbums.size() );
auto artistAlbums = artist->searchAlbums( "album", nullptr )->all();
ASSERT_EQ( 1u, artistAlbums.size() );
ASSERT_EQ( alb1->id(), artistAlbums[0]->id() );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment