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

IMediaLibrary: Remove MediaSearchAggregate type

We now return all media as a single query
parent 53d02402
......@@ -36,20 +36,12 @@ namespace medialibrary
static constexpr auto UnknownArtistID = 1u;
static constexpr auto VariousArtistID = 2u;
struct MediaSearchAggregate
{
Query<IMedia> episodes;
Query<IMedia> movies;
Query<IMedia> others;
Query<IMedia> tracks;
};
struct SearchAggregate
{
Query<IAlbum> albums;
Query<IArtist> artists;
Query<IGenre> genres;
MediaSearchAggregate media;
Query<IMedia> media;
Query<IPlaylist> playlists;
};
......@@ -330,7 +322,7 @@ class IMediaLibrary
* Passing nullptr will default to default ascending sort
* @return
*/
virtual MediaSearchAggregate searchMedia( const std::string& pattern,
virtual Query<IMedia> searchMedia( const std::string& pattern,
const QueryParameters* params = nullptr ) const = 0;
virtual Query<IMedia> searchAudio( const std::string& pattern, const QueryParameters* params = nullptr ) const = 0;
virtual Query<IMedia> searchVideo( const std::string& pattern, const QueryParameters* params = nullptr ) const = 0;
......
......@@ -677,7 +677,7 @@ bool Media::removeLabel( LabelPtr label )
}
Query<IMedia> Media::search( MediaLibraryPtr ml, const std::string& title,
Media::SubType subType, const QueryParameters* params )
const QueryParameters* params )
{
std::string req = "FROM " + policy::MediaTable::Name + " m "
" INNER JOIN " + policy::FileTable::Name + " f ON m.id_media = f.media_id"
......@@ -685,10 +685,9 @@ Query<IMedia> Media::search( MediaLibraryPtr ml, const std::string& title,
" m.id_media IN (SELECT rowid FROM " + policy::MediaTable::Name + "Fts"
" WHERE " + policy::MediaTable::Name + "Fts MATCH '*' || ? || '*')"
" AND f.is_present = 1"
" AND f.type = ?"
" AND m.subtype = ?";
" AND f.type = ?";
req += sortRequest( params );
return make_query<Media, IMedia>( ml, "m.*", req, title, File::Type::Main, subType );
return make_query<Media, IMedia>( ml, "m.*", req, title, File::Type::Main );
}
Query<IMedia> Media::search( MediaLibraryPtr ml, const std::string& title,
......
......@@ -126,9 +126,9 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
static Query<IMedia> listAll(MediaLibraryPtr ml, Type type, const QueryParameters* params );
static Query<IMedia> search( MediaLibraryPtr ml, const std::string& title,
Media::SubType subType, const QueryParameters* params );
static Query<IMedia> search( MediaLibraryPtr ml, const std::string& title,
Media::Type type, const QueryParameters* params );
const QueryParameters* params );
static Query<IMedia> search(MediaLibraryPtr ml, const std::string& title,
Media::Type subType, const QueryParameters* params );
static Query<IMedia> fetchHistory( MediaLibraryPtr ml );
static void clearHistory( MediaLibraryPtr ml );
......
......@@ -706,21 +706,12 @@ bool MediaLibrary::clearHistory()
}
}
MediaSearchAggregate MediaLibrary::searchMedia( const std::string& title,
Query<IMedia> MediaLibrary::searchMedia( const std::string& title,
const QueryParameters* params ) const
{
if ( validateSearchPattern( title ) == false )
return {};
MediaSearchAggregate res;
res.episodes = Media::search( this, title, IMedia::SubType::ShowEpisode,
params );
res.movies = Media::search( this, title, IMedia::SubType::Movie,
params );
res.others = Media::search( this, title, IMedia::SubType::Unknown,
params );
res.tracks = Media::search( this, title, IMedia::SubType::AlbumTrack,
params );
return res;
return Media::search( this, title, params );
}
Query<IMedia> MediaLibrary::searchAudio( const std::string& pattern, const QueryParameters* params ) const
......
......@@ -116,7 +116,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual Query<IMedia> lastMediaPlayed() const override;
virtual bool clearHistory() override;
virtual MediaSearchAggregate searchMedia( const std::string& title,
virtual Query<IMedia> searchMedia( const std::string& title,
const QueryParameters* params ) const override;
virtual Query<IMedia> searchAudio( const std::string& pattern,
const QueryParameters* params = nullptr ) const override;
......
......@@ -160,16 +160,16 @@ TEST_F( Medias, Search )
{
ml->addMedia( "track " + std::to_string( i ) + ".mp3" );
}
auto media = ml->searchMedia( "tra", nullptr ).others->all();
auto media = ml->searchMedia( "tra", nullptr )->all();
ASSERT_EQ( 10u, media.size() );
media = ml->searchMedia( "track 1", nullptr ).others->all();
media = ml->searchMedia( "track 1", nullptr )->all();
ASSERT_EQ( 2u, media.size() );
media = ml->searchMedia( "grouik", nullptr ).others->all();
media = ml->searchMedia( "grouik", nullptr )->all();
ASSERT_EQ( 0u, media.size() );
media = ml->searchMedia( "rack", nullptr ).others->all();
media = ml->searchMedia( "rack", nullptr )->all();
ASSERT_EQ( 0u, media.size() );
}
......@@ -184,14 +184,14 @@ TEST_F( Medias, SearchAndSort )
}
ml->addMedia( "this pattern doesn't match.mp3" );
auto media = ml->searchMedia( "tra", nullptr ).others->all();
auto media = ml->searchMedia( "tra", nullptr )->all();
ASSERT_EQ( 3u, media.size() );
ASSERT_EQ( media[0]->title(), "track 1.mp3" );
ASSERT_EQ( media[1]->title(), "track 2.mp3" );
ASSERT_EQ( media[2]->title(), "track 3.mp3" );
QueryParameters params { SortingCriteria::Duration, false };
media = ml->searchMedia( "tra", &params ).others->all();
media = ml->searchMedia( "tra", &params )->all();
ASSERT_EQ( 3u, media.size() );
ASSERT_EQ( media[0]->title(), "track 3.mp3" );
ASSERT_EQ( media[1]->title(), "track 2.mp3" );
......@@ -202,16 +202,16 @@ TEST_F( Medias, SearchAfterEdit )
{
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mp3" ) );
auto media = ml->searchMedia( "media", nullptr ).others->all();
auto media = ml->searchMedia( "media", nullptr )->all();
ASSERT_EQ( 1u, media.size() );
m->setTitleBuffered( "otters are awesome" );
m->save();
media = ml->searchMedia( "media", nullptr ).others->all();
media = ml->searchMedia( "media", nullptr )->all();
ASSERT_EQ( 0u, media.size() );
media = ml->searchMedia( "otters", nullptr ).others->all();
media = ml->searchMedia( "otters", nullptr )->all();
ASSERT_EQ( 1u, media.size() );
}
......@@ -219,59 +219,59 @@ TEST_F( Medias, SearchAfterDelete )
{
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mp3" ) );
auto media = ml->searchMedia( "media", nullptr ).others->all();
auto media = ml->searchMedia( "media", nullptr )->all();
ASSERT_EQ( 1u, media.size() );
auto f = m->files()[0];
m->removeFile( static_cast<File&>( *f ) );
media = ml->searchMedia( "media", nullptr ).others->all();
media = ml->searchMedia( "media", nullptr )->all();
ASSERT_EQ( 0u, media.size() );
}
TEST_F( Medias, SearchByLabel )
{
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mkv" ) );
auto media = ml->searchMedia( "otter", nullptr ).others->all();
auto media = ml->searchMedia( "otter", nullptr )->all();
ASSERT_EQ( 0u, media.size() );
auto l = ml->createLabel( "otter" );
m->addLabel( l );
media = ml->searchMedia( "otter", nullptr ).others->all();
media = ml->searchMedia( "otter", nullptr )->all();
ASSERT_EQ( 1u, media.size() );
auto l2 = ml->createLabel( "pangolins" );
m->addLabel( l2 );
media = ml->searchMedia( "otter", nullptr ).others->all();
media = ml->searchMedia( "otter", nullptr )->all();
ASSERT_EQ( 1u, media.size() );
media = ml->searchMedia( "pangolin", nullptr ).others->all();
media = ml->searchMedia( "pangolin", nullptr )->all();
ASSERT_EQ( 1u, media.size() );
m->removeLabel( l );
media = ml->searchMedia( "otter", nullptr ).others->all();
media = ml->searchMedia( "otter", nullptr )->all();
ASSERT_EQ( 0u, media.size() );
media = ml->searchMedia( "pangolin", nullptr ).others->all();
media = ml->searchMedia( "pangolin", nullptr )->all();
ASSERT_EQ( 1u, media.size() );
m->addLabel( l );
media = ml->searchMedia( "otter", nullptr ).others->all();
media = ml->searchMedia( "otter", nullptr )->all();
ASSERT_EQ( 1u, media.size() );
media = ml->searchMedia( "pangolin", nullptr ).others->all();
media = ml->searchMedia( "pangolin", nullptr )->all();
ASSERT_EQ( 1u, media.size() );
ml->deleteLabel( l );
media = ml->searchMedia( "otter", nullptr ).others->all();
media = ml->searchMedia( "otter", nullptr )->all();
ASSERT_EQ( 0u, media.size() );
media = ml->searchMedia( "pangolin", nullptr ).others->all();
media = ml->searchMedia( "pangolin", nullptr )->all();
ASSERT_EQ( 1u, media.size() );
}
......@@ -284,16 +284,16 @@ TEST_F( Medias, SearchTracks )
a->addTrack( m, i, 1, 0, 0 );
m->save();
}
auto tracks = ml->searchMedia( "tra", nullptr ).tracks->all();
auto tracks = ml->searchMedia( "tra", nullptr )->all();
ASSERT_EQ( 10u, tracks.size() );
tracks = ml->searchMedia( "track 1", nullptr ).tracks->all();
tracks = ml->searchMedia( "track 1", nullptr )->all();
ASSERT_EQ( 2u, tracks.size() );
tracks = ml->searchMedia( "grouik", nullptr ).tracks->all();
tracks = ml->searchMedia( "grouik", nullptr )->all();
ASSERT_EQ( 0u, tracks.size() );
tracks = ml->searchMedia( "rack", nullptr ).tracks->all();
tracks = ml->searchMedia( "rack", nullptr )->all();
ASSERT_EQ( 0u, tracks.size() );
}
......
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