faster search
This commit is contained in:
parent
5a7fe3a013
commit
f3d888be35
|
@ -418,19 +418,15 @@ class PysonicSubsonicApi(object):
|
||||||
query = query.replace("*", "") # TODO handle this
|
query = query.replace("*", "") # TODO handle this
|
||||||
|
|
||||||
artists = 0
|
artists = 0
|
||||||
for item in self.library.get_artists():
|
for item in self.library.get_artists(name_contains=query):
|
||||||
if query in item["name"].lower():
|
response.add_child("artist", _parent="searchResult2", id=item["id"], name=item["name"])
|
||||||
response.add_child("artist", _parent="searchResult2", id=item["id"], name=item["name"])
|
artists += 1
|
||||||
artists += 1
|
if artists >= artistCount:
|
||||||
if artists >= artistCount:
|
break
|
||||||
break
|
|
||||||
|
|
||||||
# TODO make this more efficient
|
# TODO make this more efficient
|
||||||
albums = 0
|
albums = 0
|
||||||
for album in self.library.get_albums():
|
for album in self.library.get_albums(name_contains=query):
|
||||||
if query not in album["name"].lower():
|
|
||||||
continue
|
|
||||||
|
|
||||||
response.add_child("album", _parent="searchResult2",
|
response.add_child("album", _parent="searchResult2",
|
||||||
id=album["dir"],
|
id=album["dir"],
|
||||||
parent=album["artistdir"],
|
parent=album["artistdir"],
|
||||||
|
@ -449,10 +445,7 @@ class PysonicSubsonicApi(object):
|
||||||
|
|
||||||
# TODO make this more efficient
|
# TODO make this more efficient
|
||||||
songs = 0
|
songs = 0
|
||||||
for song in self.library.db.get_songs(): #TODO Meeee too
|
for song in self.library.db.get_songs(title_contains=query):
|
||||||
if query not in song["title"].lower():
|
|
||||||
continue
|
|
||||||
|
|
||||||
response.add_child("song", _parent="searchResult2",
|
response.add_child("song", _parent="searchResult2",
|
||||||
id=song["id"],
|
id=song["id"],
|
||||||
parent=song["albumdir"],
|
parent=song["albumdir"],
|
||||||
|
|
|
@ -192,7 +192,7 @@ class PysonicDatabase(object):
|
||||||
return libs
|
return libs
|
||||||
|
|
||||||
@readcursor
|
@readcursor
|
||||||
def get_artists(self, cursor, id=None, dirid=None, sortby="name", order=None):
|
def get_artists(self, cursor, id=None, dirid=None, sortby="name", order=None, name_contains=None):
|
||||||
assert order in ["asc", "desc", None]
|
assert order in ["asc", "desc", None]
|
||||||
artists = []
|
artists = []
|
||||||
q = "SELECT * FROM artists"
|
q = "SELECT * FROM artists"
|
||||||
|
@ -204,6 +204,9 @@ class PysonicDatabase(object):
|
||||||
if dirid:
|
if dirid:
|
||||||
conditions.append("dir = ?")
|
conditions.append("dir = ?")
|
||||||
params.append(dirid)
|
params.append(dirid)
|
||||||
|
if name_contains:
|
||||||
|
conditions.append("name LIKE ?")
|
||||||
|
params.append("%{}%".format(name_contains))
|
||||||
if conditions:
|
if conditions:
|
||||||
q += " WHERE " + " AND ".join(conditions)
|
q += " WHERE " + " AND ".join(conditions)
|
||||||
if sortby:
|
if sortby:
|
||||||
|
@ -214,7 +217,7 @@ class PysonicDatabase(object):
|
||||||
return artists
|
return artists
|
||||||
|
|
||||||
@readcursor
|
@readcursor
|
||||||
def get_albums(self, cursor, id=None, artist=None, sortby="name", order=None, limit=None):
|
def get_albums(self, cursor, id=None, artist=None, sortby="name", order=None, limit=None, name_contains=None):
|
||||||
"""
|
"""
|
||||||
:param limit: int or tuple of int, int. translates directly to sql logic.
|
:param limit: int or tuple of int, int. translates directly to sql logic.
|
||||||
"""
|
"""
|
||||||
|
@ -246,6 +249,9 @@ class PysonicDatabase(object):
|
||||||
if artist:
|
if artist:
|
||||||
conditions.append("artistid = ?")
|
conditions.append("artistid = ?")
|
||||||
params.append(artist)
|
params.append(artist)
|
||||||
|
if name_contains:
|
||||||
|
conditions.append("alb.name LIKE ?")
|
||||||
|
params.append("%{}%".format(name_contains))
|
||||||
if conditions:
|
if conditions:
|
||||||
q += " WHERE " + " AND ".join(conditions)
|
q += " WHERE " + " AND ".join(conditions)
|
||||||
|
|
||||||
|
@ -264,7 +270,7 @@ class PysonicDatabase(object):
|
||||||
return albums
|
return albums
|
||||||
|
|
||||||
@readcursor
|
@readcursor
|
||||||
def get_songs(self, cursor, id=None, genre=None, sortby="title", order=None, limit=None):
|
def get_songs(self, cursor, id=None, genre=None, sortby="title", order=None, limit=None, title_contains=None):
|
||||||
# TODO make this query massively uglier by joining albums and artists so that artistid etc can be a filter
|
# TODO make this query massively uglier by joining albums and artists so that artistid etc can be a filter
|
||||||
# or maybe lookup those IDs in the library layer?
|
# or maybe lookup those IDs in the library layer?
|
||||||
if order:
|
if order:
|
||||||
|
@ -306,6 +312,9 @@ class PysonicDatabase(object):
|
||||||
if genre:
|
if genre:
|
||||||
conditions.append("g.name = ?")
|
conditions.append("g.name = ?")
|
||||||
params.append(genre)
|
params.append(genre)
|
||||||
|
if title_contains:
|
||||||
|
conditions.append("s.title LIKE ?")
|
||||||
|
params.append("%{}%".format(title_contains))
|
||||||
if conditions:
|
if conditions:
|
||||||
q += " WHERE " + " AND ".join(conditions)
|
q += " WHERE " + " AND ".join(conditions)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue