Skip to content

Commit

Permalink
new: allow searching for local albums
Browse files Browse the repository at this point in the history
  • Loading branch information
dxstiny committed Feb 10, 2024
1 parent 01af47a commit 6c1d3d4
Show file tree
Hide file tree
Showing 124 changed files with 120 additions and 80 deletions.
6 changes: 4 additions & 2 deletions src/server/db/table/albums.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,15 @@ async def byArtist(self, artistName: str) -> List[AlbumModel]:
return await self.select(append=f"WHERE {where}")

async def search(self, query: str) -> List[AlbumModel]:
"""get songs by (non-sql) query (for the search function)"""
"""get albums by (non-sql) query (for the search function)"""

filters = query.replace("'", "''").split(";")
filter_ = ""

def createLike(word: str) -> str:
return f"(name LIKE '%{word}%')"
return (
f"(name LIKE '%{word}%' OR anyArtist LIKE '%{word}%' OR allArtists LIKE '%{word}%')"
)

ands: List[str] = []
for x in filters:
Expand Down
6 changes: 6 additions & 0 deletions src/server/meta/confidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from Levenshtein import distance as lev
from dataModel.track import ISimpleTrack
from db.table.playlists import PlaylistModel
from db.table.albums import AlbumModel


class Confidence:
Expand Down Expand Up @@ -62,6 +63,11 @@ def forPlaylist(cls, playlist: PlaylistModel, query: str, boost: float = 0) -> f
"""get relevance of playlist"""
return cls._forStrings([playlist.name], query, boost)

@classmethod
def forAlbum(cls, album: AlbumModel, query: str, boost: float = 0) -> float:
"""get relevance of playlist"""
return cls._forStrings([album.name, *album.allArtists, *album.anyArtist], query, boost)

@classmethod
def forArtist(cls, name: str, query: str, boost: float = 0) -> float:
"""get relevance of artist"""
Expand Down
19 changes: 18 additions & 1 deletion src/server/meta/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from db.database import Database
from db.table.artists import ArtistModel
from db.table.albums import AlbumModel
from dataModel.track import YoutubeTrack, ITrack
from dataModel.song import Song
from meta.spotify import Spotify, SpotifyArtist, SpotifyTrack
Expand Down Expand Up @@ -37,7 +38,7 @@ class SearchResult:

def __init__(
self,
item: ITrack | Song | ClassicPlayerPlaylist | SpotifyArtist | ArtistModel,
item: ITrack | Song | ClassicPlayerPlaylist | SpotifyArtist | ArtistModel | AlbumModel,
confidence: float,
scope: SearchScopes,
type_: SearchScopes,
Expand Down Expand Up @@ -234,6 +235,21 @@ async def _getLocalPlaylists(self) -> List[SearchResult]:
for playlist in playlists
]

async def _getLocalAlbums(self) -> List[SearchResult]:
"""get local playlists"""
if not self._scope.album:
return []
albums = await Database().albums.search(self._query)
return [
SearchResult(
album,
Confidence.forAlbum(album, self._query, boost=0.5),
SearchScopes.Local,
SearchScopes.Album,
)
for album in albums
]

async def _getSpotifyArtists(self) -> List[SearchResult]:
"""get spotify artists"""
if not self._scope.artist:
Expand Down Expand Up @@ -274,6 +290,7 @@ async def execute(self) -> None:
self._items.extend(await self._getLocalTracks())
self._items.extend(await self._getLocalPlaylists())
self._items.extend(await self._getLocalArtists())
self._items.extend(await self._getLocalAlbums())

if self._scope.youtube:
self._items.extend(await self._getYoutubeTracks())
Expand Down
1 change: 0 additions & 1 deletion src/ui/dist/assets/Album-1f347aa1.css

This file was deleted.

1 change: 1 addition & 0 deletions src/ui/dist/assets/Album-39696330.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/ui/dist/assets/Album-c485014b.js

This file was deleted.

Binary file removed src/ui/dist/assets/Album-c485014b.js.gz
Binary file not shown.
1 change: 1 addition & 0 deletions src/ui/dist/assets/Album-e93e4ab4.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added src/ui/dist/assets/Album-e93e4ab4.js.gz
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed src/ui/dist/assets/Artist-097652ba.js.gz
Binary file not shown.
Loading

0 comments on commit 6c1d3d4

Please sign in to comment.