Skip to content

feat: MBID search functionality for albums, artists and songs #4286

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

Merged
merged 3 commits into from
Jun 30, 2025

Conversation

deluan
Copy link
Member

@deluan deluan commented Jun 30, 2025

Description

This PR enhances the Subsonic API search functionality to support searching by MusicBrainz ID (MBID) for albums, artists, and media files. This improvement provides more accurate and efficient searches when users have MBID information available.

The implementation prioritizes MBID searches over full-text searches when valid UUIDs are detected, providing better search accuracy for users with MusicBrainz-tagged music libraries.

Type of Change

  • New feature

Checklist

Please review and check all that apply:

  • My code follows the project's coding style
  • I have tested the changes locally
  • I have added or updated documentation as needed
  • I have added tests that prove my fix/feature works
  • All existing and new tests pass

How to Test

  1. Start Navidrome with a music library that contains tracks with MBID metadata
  2. Use the search functionality with valid MBID values (UUIDs)
  3. Verify that searches return appropriate results for albums, artists, and tracks with matching MBIDs
  4. Run the test suite: make test PKG=./persistence/...

Technical Details

Key Changes:

  • Updated fullTextFilter function to accept additional MBID fields for enhanced search capabilities
  • Modified album, artist, and media file repositories to support MBID-based searches
  • Added database indexes for MBID fields to optimize search performance
  • Enhanced search logic to prioritize MBID matches over full-text searches when valid UUIDs are detected

Database Changes:

  • Added indexes on MBID fields (mbz_album_id, mbz_artist_id) for albums and artists
  • New migration: 20250701010107_add_mbid_indexes.sql

Code Changes:

  • persistence/sql_restful.go: Enhanced fullTextFilter to handle MBID searches
  • persistence/album_repository.go: Added MBID field to search configuration
  • persistence/artist_repository.go: Added MBID field to search configuration
  • persistence/mediafile_repository.go: Added MBID field to search configuration
  • persistence/sql_search.go: Enhanced search logic for MBID support

Test Coverage:

  • Comprehensive unit tests for fullTextFilter with MBID functionality
  • Tests covering UUID validation and MBID precedence over full-text search
  • Tests for edge cases including missing entries and various search configurations
  • Added tests in persistence/sql_restful_test.go, persistence/artist_repository_test.go, and persistence/mediafile_repository_test.go

Additional Notes

This enhancement maintains backward compatibility while improving search accuracy for users with MusicBrainz-tagged music libraries. The implementation follows the existing patterns in the codebase and includes proper error handling and comprehensive test coverage.

The feature automatically detects when a search query is a valid UUID (MBID format) and prioritizes MBID-based searches in those cases, falling back to traditional full-text search for non-UUID queries.

deluan added 2 commits June 30, 2025 15:11
Updated the search methods in the mediaFileRepository, albumRepository, and artistRepository to support searching by MBID in addition to the existing query methods. This change improves the efficiency of media file, album, and artist searches, allowing for faster retrieval of records based on MBID.

Signed-off-by: Deluan <deluan@navidrome.org>
Updated the search functionality to support searching by MBID for both
albums and artists. The fullTextFilter function was modified to accept
additional MBID fields, allowing for more comprehensive searches. New
tests were added to ensure that the search functionality correctly
handles MBID queries, including cases for missing entries and the
includeMissing parameter. This enhancement improves the overall search
capabilities of the application, making it easier for users to find
specific media items by their unique identifiers.

Signed-off-by: Deluan <deluan@navidrome.org>
@Copilot Copilot AI review requested due to automatic review settings June 30, 2025 20:33
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @deluan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a major enhancement to the search capabilities by integrating MusicBrainz ID (MBID) support across albums, artists, and media files. The core idea is to leverage standardized metadata identifiers for more precise and performant searches, automatically prioritizing MBID lookups when a valid UUID is provided as a query. This change includes necessary database schema updates, modifications to the underlying search logic, and comprehensive testing to ensure reliability and backward compatibility.

Highlights

  • Enhanced Search Functionality: The Subsonic API search has been significantly enhanced to support searching by MusicBrainz ID (MBID) for albums, artists, and media files. This provides more accurate and efficient results for users with MusicBrainz-tagged libraries.
  • MBID Search Prioritization: When a search query is detected as a valid UUID (MBID format), the system now prioritizes MBID-based searches over traditional full-text searches, ensuring direct and precise matches.
  • Database Indexing for Performance: New database indexes have been added to mbz_artist_id, mbz_album_id, and mbz_release_track_id fields in the artist, album, and media_file tables, respectively, to optimize the performance of MBID lookups.
  • Refactored Search Logic: The fullTextFilter function has been updated to accept additional MBID fields, and a new searchByMBID method along with an mbidExpr helper function have been introduced in sql_search.go to encapsulate the MBID-specific search logic.
  • Comprehensive Test Coverage: New unit tests have been added for the fullTextFilter with MBID functionality, covering UUID validation, MBID precedence, and edge cases, ensuring the robustness of the new search capabilities.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the Subsonic API search functionality by adding support for MusicBrainz ID (MBID)–based searches across albums, artists, and media files. Key changes include:

  • Introducing new MBID search functions (searchByMBID and mbidExpr) to prioritize valid UUID queries.
  • Updating repository Search methods to leverage MBID filtering and adding corresponding database indexes.
  • Expanding test coverage to verify MBID search behavior and consistency with full-text searches.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
persistence/sql_search.go Added MBID search functions (searchByMBID and mbidExpr) for MBID-based filtering
persistence/sql_restful.go Updated fullTextFilter to accept MBID fields and build a combined condition
persistence/sql_restful_test.go Extended tests to cover MBID and full-text filtering behavior
persistence/mediafile_repository.go Modified Search to use MBID filtering when a valid UUID is detected
persistence/artist_repository.go Modified Search to use MBID filtering when a valid UUID is detected
persistence/album_repository.go Modified Search to use MBID filtering when a valid UUID is detected
db/migrations/20250701010107_add_mbid_indexes.sql Added indexes for MBID fields to optimize search performance

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces MBID search functionality, enhancing search accuracy and efficiency. The implementation includes database indexes and tests. However, the searchByMBID function is missing pagination, and the fullTextFilter function could be more efficient by prioritizing MBID searches.

Updated the MBID handling in the SQL search logic to convert the input
to lowercase before executing the query. This change ensures that
searches are case-insensitive, improving the accuracy and reliability
of the search results when querying by MBID.

Signed-off-by: Deluan <deluan@navidrome.org>
@deluan deluan changed the title feat(subsonic): enhance MBID search functionality for albums and artists feat(subsonic): MBID search functionality for albums and artists Jun 30, 2025
@deluan deluan changed the title feat(subsonic): MBID search functionality for albums and artists feat(subsonic): MBID search functionality for albums, artists and mediaFiles Jun 30, 2025
@deluan deluan changed the title feat(subsonic): MBID search functionality for albums, artists and mediaFiles feat: MBID search functionality for albums, artists and songs Jun 30, 2025
@deluan deluan merged commit bfa5b29 into master Jun 30, 2025
35 checks passed
@deluan deluan deleted the search-by-mbid branch June 30, 2025 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant