mirror of
https://github.com/krateng/maloja.git
synced 2025-07-09 03:04:07 -04:00
Added albums to search
This commit is contained in:
parent
688cac81ee
commit
d860e19b54
@ -592,6 +592,7 @@ def search(**keys):
|
|||||||
|
|
||||||
artists = database.db_search(query,type="ARTIST")
|
artists = database.db_search(query,type="ARTIST")
|
||||||
tracks = database.db_search(query,type="TRACK")
|
tracks = database.db_search(query,type="TRACK")
|
||||||
|
albums = database.db_search(query,type="ALBUM")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -599,6 +600,7 @@ def search(**keys):
|
|||||||
# also, shorter is better (because longer titles would be easier to further specify)
|
# also, shorter is better (because longer titles would be easier to further specify)
|
||||||
artists.sort(key=lambda x: ((0 if x.lower().startswith(query) else 1 if " " + query in x.lower() else 2),len(x)))
|
artists.sort(key=lambda x: ((0 if x.lower().startswith(query) else 1 if " " + query in x.lower() else 2),len(x)))
|
||||||
tracks.sort(key=lambda x: ((0 if x["title"].lower().startswith(query) else 1 if " " + query in x["title"].lower() else 2),len(x["title"])))
|
tracks.sort(key=lambda x: ((0 if x["title"].lower().startswith(query) else 1 if " " + query in x["title"].lower() else 2),len(x["title"])))
|
||||||
|
albums.sort(key=lambda x: ((0 if x["albumtitle"].lower().startswith(query) else 1 if " " + query in x["albumtitle"].lower() else 2),len(x["albumtitle"])))
|
||||||
|
|
||||||
# add links
|
# add links
|
||||||
artists_result = []
|
artists_result = []
|
||||||
@ -619,7 +621,17 @@ def search(**keys):
|
|||||||
}
|
}
|
||||||
tracks_result.append(result)
|
tracks_result.append(result)
|
||||||
|
|
||||||
return {"artists":artists_result[:max_],"tracks":tracks_result[:max_]}
|
albums_result = []
|
||||||
|
for al in albums:
|
||||||
|
result = {
|
||||||
|
'album': al,
|
||||||
|
'link': "/album?" + compose_querystring(internal_to_uri({"album":al})),
|
||||||
|
'image': images.get_album_image(al)
|
||||||
|
}
|
||||||
|
if not result['album']['artists']: result['album']['displayArtist'] = malojaconfig["DEFAULT_ALBUM_ARTIST"]
|
||||||
|
albums_result.append(result)
|
||||||
|
|
||||||
|
return {"artists":artists_result[:max_],"tracks":tracks_result[:max_],"albums":albums_result[:max_]}
|
||||||
|
|
||||||
|
|
||||||
@api.post("newrule")
|
@api.post("newrule")
|
||||||
|
@ -580,4 +580,7 @@ def db_search(query,type=None):
|
|||||||
results = sqldb.search_artist(query)
|
results = sqldb.search_artist(query)
|
||||||
if type=="TRACK":
|
if type=="TRACK":
|
||||||
results = sqldb.search_track(query)
|
results = sqldb.search_track(query)
|
||||||
|
if type=="ALBUM":
|
||||||
|
results = sqldb.search_album(query)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
@ -1214,6 +1214,15 @@ def search_track(searchterm,dbconn=None):
|
|||||||
|
|
||||||
return [get_track(row.id,dbconn=dbconn) for row in result]
|
return [get_track(row.id,dbconn=dbconn) for row in result]
|
||||||
|
|
||||||
|
@cached_wrapper
|
||||||
|
@connection_provider
|
||||||
|
def search_album(searchterm,dbconn=None):
|
||||||
|
op = DB['albums'].select().where(
|
||||||
|
DB['albums'].c.albtitle_normalized.ilike(normalize_name(f"%{searchterm}%"))
|
||||||
|
)
|
||||||
|
result = dbconn.execute(op).all()
|
||||||
|
|
||||||
|
return [get_album(row.id,dbconn=dbconn) for row in result]
|
||||||
|
|
||||||
##### MAINTENANCE
|
##### MAINTENANCE
|
||||||
|
|
||||||
|
@ -82,6 +82,10 @@
|
|||||||
<span>Tracks</span>
|
<span>Tracks</span>
|
||||||
<table class="searchresults_tracks" id="searchresults_tracks">
|
<table class="searchresults_tracks" id="searchresults_tracks">
|
||||||
</table>
|
</table>
|
||||||
|
<br/><br/>
|
||||||
|
<span>Albums</span>
|
||||||
|
<table class="searchresults_albums" id="searchresults_albums">
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -23,11 +23,13 @@ function html_to_fragment(html) {
|
|||||||
|
|
||||||
var results_artists;
|
var results_artists;
|
||||||
var results_tracks;
|
var results_tracks;
|
||||||
|
var results_albums;
|
||||||
var searchresultwrap;
|
var searchresultwrap;
|
||||||
|
|
||||||
window.addEventListener("DOMContentLoaded",function(){
|
window.addEventListener("DOMContentLoaded",function(){
|
||||||
results_artists = document.getElementById("searchresults_artists");
|
results_artists = document.getElementById("searchresults_artists");
|
||||||
results_tracks = document.getElementById("searchresults_tracks");
|
results_tracks = document.getElementById("searchresults_tracks");
|
||||||
|
results_albums = document.getElementById("searchresults_albums");
|
||||||
searchresultwrap = document.getElementById("resultwrap");
|
searchresultwrap = document.getElementById("resultwrap");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -50,8 +52,9 @@ function searchresult() {
|
|||||||
// any older searches are now rendered irrelevant
|
// any older searches are now rendered irrelevant
|
||||||
while (searches[0] != this) { searches.splice(0,1) }
|
while (searches[0] != this) { searches.splice(0,1) }
|
||||||
var result = JSON.parse(this.responseText);
|
var result = JSON.parse(this.responseText);
|
||||||
var artists = result["artists"].slice(0,5)
|
var artists = result["artists"].slice(0,4)
|
||||||
var tracks = result["tracks"].slice(0,5)
|
var tracks = result["tracks"].slice(0,4)
|
||||||
|
var albums = result["albums"].slice(0,4)
|
||||||
|
|
||||||
while (results_artists.firstChild) {
|
while (results_artists.firstChild) {
|
||||||
results_artists.removeChild(results_artists.firstChild);
|
results_artists.removeChild(results_artists.firstChild);
|
||||||
@ -59,6 +62,9 @@ function searchresult() {
|
|||||||
while (results_tracks.firstChild) {
|
while (results_tracks.firstChild) {
|
||||||
results_tracks.removeChild(results_tracks.firstChild);
|
results_tracks.removeChild(results_tracks.firstChild);
|
||||||
}
|
}
|
||||||
|
while (results_albums.firstChild) {
|
||||||
|
results_albums.removeChild(results_albums.firstChild);
|
||||||
|
}
|
||||||
|
|
||||||
for (var i=0;i<artists.length;i++) {
|
for (var i=0;i<artists.length;i++) {
|
||||||
name = artists[i]["artist"];
|
name = artists[i]["artist"];
|
||||||
@ -87,6 +93,21 @@ function searchresult() {
|
|||||||
|
|
||||||
results_tracks.appendChild(node);
|
results_tracks.appendChild(node);
|
||||||
}
|
}
|
||||||
|
for (var i=0;i<albums.length;i++) {
|
||||||
|
|
||||||
|
artists = albums[i]["album"].hasOwnProperty("displayArtist") ? albums[i]["album"]["displayArtist"] : albums[i]["album"]["artists"].join(", ");
|
||||||
|
albumtitle = albums[i]["album"]["albumtitle"];
|
||||||
|
link = albums[i]["link"];
|
||||||
|
image = albums[i]["image"];
|
||||||
|
|
||||||
|
var node = oneresult.cloneNode(true);
|
||||||
|
node.setAttribute("onclick","goto('" + link + "')");
|
||||||
|
node.children[0].style.backgroundImage = "url('" + image + "')";
|
||||||
|
node.children[1].children[0].textContent = artists;
|
||||||
|
node.children[1].children[2].textContent = albumtitle;
|
||||||
|
|
||||||
|
results_albums.appendChild(node);
|
||||||
|
}
|
||||||
searchresultwrap.classList.remove("hide")
|
searchresultwrap.classList.remove("hide")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user