feat(subsonic): allow search with MBID (#579)

* feat(search): use search2/3 query to additionally search track MBID

* feat(search): use strict equality for MBID search

don't compare substrings for now to reduce unwanted results based on
MBIDs

might also make search more efficient

* feat(db): add migration to create index on MBID

for MBID search

* tweak(search): remove unnecessary trim on query
This commit is contained in:
gabe
2025-05-26 14:38:25 +00:00
committed by GitHub
parent 19b707c5d4
commit 2d4111dfc5
3 changed files with 9 additions and 2 deletions

No files matched your search

+7
View File
@@ -77,6 +77,7 @@ func (db *DB) Migrate(ctx MigrationContext) error {
construct(ctx, "202501152036", migrateAlbumAddIndexOnParentID),
construct(ctx, "202502012036", migratePodcastEpisode),
construct(ctx, "202504132036", migratePodcast),
construct(ctx, "202505211202", migrateTrackAddIndexOnBrainzID),
}
return gormigrate.
@@ -840,3 +841,9 @@ func migratePodcastEpisode(tx *gorm.DB, _ MigrationContext) error {
PodcastEpisode{},
).Error
}
func migrateTrackAddIndexOnBrainzID(tx *gorm.DB, _ MigrationContext) error {
return tx.Exec(`
CREATE INDEX idx_tracks_brainz_id ON "tracks" (tag_brainz_id);
`).Error
}
+1 -1
View File
@@ -263,7 +263,7 @@ func (c *Controller) ServeSearchTwo(r *http.Request) *spec.Response {
var tracks []*db.Track
q = c.dbc.Preload("Album")
for _, s := range queries {
q = q.Where(`filename LIKE ? OR filename LIKE ?`, s, s)
q = q.Where(`filename LIKE ? OR filename LIKE ? OR tag_brainz_id = ?`, s, s, query)
}
q = q.
Preload("Artists").
+1 -1
View File
@@ -287,7 +287,7 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response {
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID)
for _, s := range queries {
q = q.Where(`tracks.tag_title LIKE ? OR tracks.tag_title_u_dec LIKE ?`, s, s)
q = q.Where(`tracks.tag_title LIKE ? OR tracks.tag_title_u_dec LIKE ? OR tracks.tag_brainz_id = ?`, s, s, query)
}
q = q.Offset(params.GetOrInt("songOffset", 0)).
Limit(params.GetOrInt("songCount", 20))