diff --git a/supysonic/api/search.py b/supysonic/api/search.py index cf2ff5b..dedb544 100644 --- a/supysonic/api/search.py +++ b/supysonic/api/search.py @@ -200,9 +200,14 @@ def search_id3(): song_offset = int(song_offset) if song_offset else 0 root = get_root_folder(mfid) - artists = Artist.select().where(Artist.name.contains(query)) - albums = Album.select().where(Album.name.contains(query)) - songs = Track.select().where(Track.title.contains(query)) + artists = Artist.select() + albums = Album.select() + songs = Track.select() + + if query: + artists = artists.where(Artist.name.contains(query)) + albums = albums.where(Album.name.contains(query)) + songs = songs.where(Track.title.contains(query)) if root is not None: artists = artists.join(Track).where(Track.root_folder == root) diff --git a/tests/api/test_search.py b/tests/api/test_search.py index 6c9167a..7a1aab8 100644 --- a/tests/api/test_search.py +++ b/tests/api/test_search.py @@ -420,6 +420,12 @@ class SearchTestCase(ApiTestBase): ) self.assertEqual(len(self._xpath(child, "./song")), 0) + # empty query + rv, child = self._make_request("search3", {"query": ""}, tag="searchResult3") + self.assertEqual(len(child), 27) # 3 + 3*2 + 3*2*3 + self.assertEqual(len(self._xpath(child, "./artist")), 3) + self.assertEqual(len(self._xpath(child, "./album")), 6) + self.assertEqual(len(self._xpath(child, "./song")), 18) if __name__ == "__main__": unittest.main()