mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 17:06:17 +00:00
Support for empty search3 queries
We already did (at least with SQLite), make sure it's the case (ie: test it) and prevent useless WHERE when querying the database
This commit is contained in:
parent
1271b30d64
commit
88997d5984
@ -200,9 +200,14 @@ def search_id3():
|
|||||||
song_offset = int(song_offset) if song_offset else 0
|
song_offset = int(song_offset) if song_offset else 0
|
||||||
root = get_root_folder(mfid)
|
root = get_root_folder(mfid)
|
||||||
|
|
||||||
artists = Artist.select().where(Artist.name.contains(query))
|
artists = Artist.select()
|
||||||
albums = Album.select().where(Album.name.contains(query))
|
albums = Album.select()
|
||||||
songs = Track.select().where(Track.title.contains(query))
|
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:
|
if root is not None:
|
||||||
artists = artists.join(Track).where(Track.root_folder == root)
|
artists = artists.join(Track).where(Track.root_folder == root)
|
||||||
|
@ -420,6 +420,12 @@ class SearchTestCase(ApiTestBase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(len(self._xpath(child, "./song")), 0)
|
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__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user