1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Moved search functionality to database

This commit is contained in:
krateng 2022-04-23 16:36:35 +02:00
parent 528d3565b7
commit db8bf60aef
2 changed files with 20 additions and 2 deletions

View File

@ -423,7 +423,7 @@ def start_db():
def db_search(query,type=None): def db_search(query,type=None):
results = [] results = []
if type=="ARTIST": if type=="ARTIST":
results = [a for a in sqldb.get_artists() if sqldb.normalize_name(query) in sqldb.normalize_name(a)] results = sqldb.search_artist(query)
if type=="TRACK": if type=="TRACK":
results = [t for t in sqldb.get_tracks() if sqldb.normalize_name(query) in sqldb.normalize_name(t['title'])] results = sqldb.search_track(query)
return results return results

View File

@ -691,7 +691,25 @@ def get_artist(id,dbconn=None):
return artist_db_to_dict(artistinfo,dbconn=dbconn) return artist_db_to_dict(artistinfo,dbconn=dbconn)
@cached_wrapper
@connection_provider
def search_artist(searchterm,dbconn=None):
op = DB['artists'].select().where(
DB['artists'].c.name_normalized.ilike(normalize_name(f"%{searchterm}%"))
)
result = dbconn.execute(op).all()
return [get_artist(row.id,dbconn=dbconn) for row in result]
@cached_wrapper
@connection_provider
def search_track(searchterm,dbconn=None):
op = DB['tracks'].select().where(
DB['tracks'].c.title_normalized.ilike(normalize_name(f"%{searchterm}%"))
)
result = dbconn.execute(op).all()
return [get_track(row.id,dbconn=dbconn) for row in result]
##### MAINTENANCE ##### MAINTENANCE