Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Albums and Artists in Search Results #16

Open
tkem opened this issue Oct 12, 2014 · 3 comments
Open

Include Albums and Artists in Search Results #16

tkem opened this issue Oct 12, 2014 · 3 comments
Labels
C-enhancement Category: A PR with an enhancement or an issue with an enhancement proposal

Comments

@tkem
Copy link
Member

tkem commented Oct 12, 2014

Depends on mopidy/mopidy#840, since clients may want to lookup() search result items.

@chrisgee
Copy link

chrisgee commented Mar 5, 2017

any plans to add this? I have a (stupid) patch that yields Albums and Artists of the found tracks. Of course this may be incomplete as not all matching tracks for the search are returned. Anyway here is my patch:

diff --git a/mopidy_local_sqlite/library.py b/mopidy_local_sqlite/library.py
index 594068b..312961b 100644
--- a/mopidy_local_sqlite/library.py
+++ b/mopidy_local_sqlite/library.py
@@ -79,8 +79,18 @@ class SQLiteLibrary(local.Library):
         filters = [f for uri in uris or [] for f in self._filters(uri) if f]
         with self._connect() as c:
             tracks = schema.search_tracks(c, q, limit, offset, exact, filters)
+        #extract album and artist data from the search result
+        #fixme: this only yields albums and artists that are referenced by the 
+        #tracks result, which may be incomplete in case there is more than limit
+        #matching entries. To get the right behaviour, FTS should be implemented
+        #for artists and albums as well... (in the sql schema)
+        albums = set()
+        artists = set()
+        for t in tracks:
+            albums.add(t.album)
+            artists.add(t.artist)
         uri = uritools.uricompose('local', path='search', query=q)
-        return SearchResult(uri=uri, tracks=tracks)
+        return SearchResult(uri=uri, tracks=tracks, artists = artists, albums = albums)
 
     def get_distinct(self, field, query=None):
         q = []

I am sure, a proper solution would be to implement FTS for album and artist tables. But as I am not fluent in SQL, that's beyond my capabilities

@tkem
Copy link
Member Author

tkem commented Mar 9, 2017

Thanks for sharing, but this wasn't exactly what I had in mind, though I see that it will improve things somewhat for some use cases.

I'd refrain from merging this though, because of the number of false positives it generates - for example, if the search string is found only in one track's title, I wouldn't expect the track's album to be part of the result.

@tkem
Copy link
Member Author

tkem commented Mar 9, 2017

@chrisgee: The really tricky part is not just implementing this in SQL/FTS, but doing so efficiently, so it will run with medium-sized libraries (say 10,000 - 100,000 tracks) on a Pi0 in less than a second or so ;-)

@tkem tkem transferred this issue from mopidy/mopidy-local-sqlite Dec 9, 2019
@jodal jodal added the C-enhancement Category: A PR with an enhancement or an issue with an enhancement proposal label Dec 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: A PR with an enhancement or an issue with an enhancement proposal
Projects
None yet
Development

No branches or pull requests

3 participants