mirror of
https://github.com/navidrome/navidrome.git
synced 2025-07-13 23:21:21 +03:00
* feat(subsonic): search by MBID functionality 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> * feat(subsonic): enhance MBID search functionality for albums and artists 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> * fix(subsonic): normalize MBID to lowercase for consistent querying 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> --------- Signed-off-by: Deluan <deluan@navidrome.org>
79 lines
2.0 KiB
Go
79 lines
2.0 KiB
Go
package persistence
|
|
|
|
import (
|
|
"strings"
|
|
|
|
. "github.com/Masterminds/squirrel"
|
|
"github.com/google/uuid"
|
|
"github.com/navidrome/navidrome/conf"
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/navidrome/navidrome/utils/str"
|
|
)
|
|
|
|
func formatFullText(text ...string) string {
|
|
fullText := str.SanitizeStrings(text...)
|
|
return " " + fullText
|
|
}
|
|
|
|
func (r sqlRepository) doSearch(sq SelectBuilder, q string, offset, size int, includeMissing bool, results any, orderBys ...string) error {
|
|
q = strings.TrimSpace(q)
|
|
q = strings.TrimSuffix(q, "*")
|
|
if len(q) < 2 {
|
|
return nil
|
|
}
|
|
|
|
filter := fullTextExpr(r.tableName, q)
|
|
if filter != nil {
|
|
sq = sq.Where(filter)
|
|
sq = sq.OrderBy(orderBys...)
|
|
} else {
|
|
// If the filter is empty, we sort by rowid.
|
|
// This is to speed up the results of `search3?query=""`, for OpenSubsonic
|
|
sq = sq.OrderBy(r.tableName + ".rowid")
|
|
}
|
|
if !includeMissing {
|
|
sq = sq.Where(Eq{r.tableName + ".missing": false})
|
|
}
|
|
sq = sq.Limit(uint64(size)).Offset(uint64(offset))
|
|
return r.queryAll(sq, results, model.QueryOptions{Offset: offset})
|
|
}
|
|
|
|
func (r sqlRepository) searchByMBID(sq SelectBuilder, mbid string, mbidFields []string, includeMissing bool, results any) error {
|
|
sq = sq.Where(mbidExpr(r.tableName, mbid, mbidFields...))
|
|
|
|
if !includeMissing {
|
|
sq = sq.Where(Eq{r.tableName + ".missing": false})
|
|
}
|
|
|
|
return r.queryAll(sq, results)
|
|
}
|
|
|
|
func mbidExpr(tableName, mbid string, mbidFields ...string) Sqlizer {
|
|
if uuid.Validate(mbid) != nil || len(mbidFields) == 0 {
|
|
return nil
|
|
}
|
|
mbid = strings.ToLower(mbid)
|
|
var cond []Sqlizer
|
|
for _, mbidField := range mbidFields {
|
|
cond = append(cond, Eq{tableName + "." + mbidField: mbid})
|
|
}
|
|
return Or(cond)
|
|
}
|
|
|
|
func fullTextExpr(tableName string, s string) Sqlizer {
|
|
q := str.SanitizeStrings(s)
|
|
if q == "" {
|
|
return nil
|
|
}
|
|
var sep string
|
|
if !conf.Server.SearchFullString {
|
|
sep = " "
|
|
}
|
|
parts := strings.Split(q, " ")
|
|
filters := And{}
|
|
for _, part := range parts {
|
|
filters = append(filters, Like{tableName + ".full_text": "%" + sep + part + "%"})
|
|
}
|
|
return filters
|
|
}
|