Commit 24e8f45e authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

Use a more permissive search

And use SQL to concanate string, as the compiled request will be cached.
parent e80a85ad
...@@ -437,9 +437,9 @@ std::vector<AlbumPtr> Album::search( MediaLibraryPtr ml, const std::string& patt ...@@ -437,9 +437,9 @@ std::vector<AlbumPtr> Album::search( MediaLibraryPtr ml, const std::string& patt
{ {
static const std::string req = "SELECT * FROM " + policy::AlbumTable::Name + " WHERE id_album IN " static const std::string req = "SELECT * FROM " + policy::AlbumTable::Name + " WHERE id_album IN "
"(SELECT rowid FROM " + policy::AlbumTable::Name + "Fts WHERE " + "(SELECT rowid FROM " + policy::AlbumTable::Name + "Fts WHERE " +
policy::AlbumTable::Name + "Fts MATCH ?)" policy::AlbumTable::Name + "Fts MATCH '*' || ? || '*')"
"AND is_present = 1"; "AND is_present = 1";
return fetchAll<IAlbum>( ml, req, pattern + "*" ); return fetchAll<IAlbum>( ml, req, pattern );
} }
std::vector<AlbumPtr> Album::fromArtist( MediaLibraryPtr ml, int64_t artistId, SortingCriteria sort, bool desc ) std::vector<AlbumPtr> Album::fromArtist( MediaLibraryPtr ml, int64_t artistId, SortingCriteria sort, bool desc )
......
...@@ -270,9 +270,9 @@ std::shared_ptr<Artist> Artist::create( MediaLibraryPtr ml, const std::string &n ...@@ -270,9 +270,9 @@ std::shared_ptr<Artist> Artist::create( MediaLibraryPtr ml, const std::string &n
std::vector<ArtistPtr> Artist::search( MediaLibraryPtr ml, const std::string& name ) std::vector<ArtistPtr> Artist::search( MediaLibraryPtr ml, const std::string& name )
{ {
static const std::string req = "SELECT * FROM " + policy::ArtistTable::Name + " WHERE id_artist IN " static const std::string req = "SELECT * FROM " + policy::ArtistTable::Name + " WHERE id_artist IN "
"(SELECT rowid FROM " + policy::ArtistTable::Name + "Fts WHERE name MATCH ?)" "(SELECT rowid FROM " + policy::ArtistTable::Name + "Fts WHERE name MATCH '*' || ? || '*')"
"AND is_present != 0"; "AND is_present != 0";
return fetchAll<IArtist>( ml, req, name + "*" ); return fetchAll<IArtist>( ml, req, name );
} }
std::vector<ArtistPtr> Artist::listAll(MediaLibraryPtr ml, SortingCriteria sort, bool desc) std::vector<ArtistPtr> Artist::listAll(MediaLibraryPtr ml, SortingCriteria sort, bool desc)
......
...@@ -132,8 +132,8 @@ std::shared_ptr<Genre> Genre::fromName( MediaLibraryPtr ml, const std::string& n ...@@ -132,8 +132,8 @@ std::shared_ptr<Genre> Genre::fromName( MediaLibraryPtr ml, const std::string& n
std::vector<GenrePtr> Genre::search( MediaLibraryPtr ml, const std::string& name ) std::vector<GenrePtr> Genre::search( MediaLibraryPtr ml, const std::string& name )
{ {
static const std::string req = "SELECT * FROM " + policy::GenreTable::Name + " WHERE id_genre IN " static const std::string req = "SELECT * FROM " + policy::GenreTable::Name + " WHERE id_genre IN "
"(SELECT rowid FROM " + policy::GenreTable::Name + "Fts WHERE name MATCH ?)"; "(SELECT rowid FROM " + policy::GenreTable::Name + "Fts WHERE name MATCH '*' || ? || '*')";
return fetchAll<IGenre>( ml, req, name + "*" ); return fetchAll<IGenre>( ml, req, name );
} }
std::vector<GenrePtr> Genre::listAll( MediaLibraryPtr ml, SortingCriteria, bool desc ) std::vector<GenrePtr> Genre::listAll( MediaLibraryPtr ml, SortingCriteria, bool desc )
......
...@@ -537,9 +537,9 @@ std::vector<MediaPtr> Media::search( MediaLibraryPtr ml, const std::string& titl ...@@ -537,9 +537,9 @@ std::vector<MediaPtr> Media::search( MediaLibraryPtr ml, const std::string& titl
{ {
static const std::string req = "SELECT * FROM " + policy::MediaTable::Name + " WHERE" static const std::string req = "SELECT * FROM " + policy::MediaTable::Name + " WHERE"
" id_media IN (SELECT rowid FROM " + policy::MediaTable::Name + "Fts" " id_media IN (SELECT rowid FROM " + policy::MediaTable::Name + "Fts"
" WHERE " + policy::MediaTable::Name + "Fts MATCH ?)" " WHERE " + policy::MediaTable::Name + "Fts MATCH '*' || ? || '*')"
"AND is_present = 1"; "AND is_present = 1";
return Media::fetchAll<IMedia>( ml, req, title + "*" ); return Media::fetchAll<IMedia>( ml, req, title );
} }
std::vector<MediaPtr> Media::fetchHistory( MediaLibraryPtr ml ) std::vector<MediaPtr> Media::fetchHistory( MediaLibraryPtr ml )
......
...@@ -224,8 +224,8 @@ bool Playlist::createTriggers( DBConnection dbConn ) ...@@ -224,8 +224,8 @@ bool Playlist::createTriggers( DBConnection dbConn )
std::vector<PlaylistPtr> Playlist::search( MediaLibraryPtr ml, const std::string& name ) std::vector<PlaylistPtr> Playlist::search( MediaLibraryPtr ml, const std::string& name )
{ {
static const std::string req = "SELECT * FROM " + policy::PlaylistTable::Name + " WHERE id_playlist IN " static const std::string req = "SELECT * FROM " + policy::PlaylistTable::Name + " WHERE id_playlist IN "
"(SELECT rowid FROM " + policy::PlaylistTable::Name + "Fts WHERE name MATCH ?)"; "(SELECT rowid FROM " + policy::PlaylistTable::Name + "Fts WHERE name MATCH '*' || ? || '*')";
return fetchAll<IPlaylist>( ml, req, name + "*" ); return fetchAll<IPlaylist>( ml, req, name );
} }
std::vector<PlaylistPtr> Playlist::listAll( MediaLibraryPtr ml, SortingCriteria sort, bool desc ) std::vector<PlaylistPtr> Playlist::listAll( MediaLibraryPtr ml, SortingCriteria sort, bool desc )
......
Supports Markdown
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