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

Media: Don't return external media as part of search results

parent 9b04db19
......@@ -320,7 +320,10 @@ class IMediaLibrary
* - FileSize
* Default sorting parameter uses the media's title.
* Passing nullptr will default to default ascending sort
* @return
*
* Only media that were discovered by the medialibrary will be included.
* For instance, media that are added explicitely, playlist items that
* point to remote content, will *not* be included
*/
virtual Query<IMedia> searchMedia( const std::string& pattern,
const QueryParameters* params = nullptr ) const = 0;
......
......@@ -685,9 +685,11 @@ 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 f.type = ?"
" AND m.type != ?";
req += sortRequest( params );
return make_query<Media, IMedia>( ml, "m.*", req, title, File::Type::Main );
return make_query<Media, IMedia>( ml, "m.*", req, title, File::Type::Main,
Media::Type::External );
}
Query<IMedia> Media::search( MediaLibraryPtr ml, const std::string& title,
......
......@@ -158,7 +158,10 @@ TEST_F( Medias, Search )
{
for ( auto i = 1u; i <= 10u; ++i )
{
ml->addMedia( "track " + std::to_string( i ) + ".mp3" );
auto m = std::static_pointer_cast<Media>(
ml->addMedia( "track " + std::to_string( i ) + ".mp3" ) );
m->setType( IMedia::Type::Video );
m->save();
}
auto media = ml->searchMedia( "tra", nullptr )->all();
ASSERT_EQ( 10u, media.size() );
......@@ -179,10 +182,13 @@ TEST_F( Medias, SearchAndSort )
{
auto m = std::static_pointer_cast<Media>(
ml->addMedia( "track " + std::to_string( i ) + ".mp3" ) );
m->setType( IMedia::Type::Audio );
m->setDuration( 3 - i );
m->save();
}
ml->addMedia( "this pattern doesn't match.mp3" );
auto m = std::static_pointer_cast<Media>( ml->addMedia( "this pattern doesn't match.mp3" ) );
m->setType( IMedia::Type::Audio );
m->save();
auto media = ml->searchMedia( "tra", nullptr )->all();
ASSERT_EQ( 3u, media.size() );
......@@ -201,6 +207,8 @@ TEST_F( Medias, SearchAndSort )
TEST_F( Medias, SearchAfterEdit )
{
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mp3" ) );
m->setType( IMedia::Type::Audio );
m->save();
auto media = ml->searchMedia( "media", nullptr )->all();
ASSERT_EQ( 1u, media.size() );
......@@ -218,6 +226,8 @@ TEST_F( Medias, SearchAfterEdit )
TEST_F( Medias, SearchAfterDelete )
{
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mp3" ) );
m->setType( IMedia::Type::Audio );
m->save();
auto media = ml->searchMedia( "media", nullptr )->all();
ASSERT_EQ( 1u, media.size() );
......@@ -232,6 +242,8 @@ TEST_F( Medias, SearchAfterDelete )
TEST_F( Medias, SearchByLabel )
{
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mkv" ) );
m->setType( IMedia::Type::Video );
m->save();
auto media = ml->searchMedia( "otter", nullptr )->all();
ASSERT_EQ( 0u, media.size() );
......@@ -282,6 +294,7 @@ TEST_F( Medias, SearchTracks )
{
auto m = std::static_pointer_cast<Media>( ml->addMedia( "track " + std::to_string( i ) + ".mp3" ) );
a->addTrack( m, i, 1, 0, 0 );
m->setType( IMedia::Type::Audio );
m->save();
}
auto tracks = ml->searchMedia( "tra", nullptr )->all();
......@@ -299,7 +312,9 @@ TEST_F( Medias, SearchTracks )
TEST_F( Medias, Favorite )
{
auto m = ml->addMedia( "media.mkv" );
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mkv" ) );
m->setType( IMedia::Type::Video );
m->save();
ASSERT_FALSE( m->isFavorite() );
m->setFavorite( true );
......
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