fix: find songs and albums when sending an artist name search query

This commit is contained in:
Deluan 2020-02-09 19:52:06 -05:00
parent ce11a2f3be
commit 8a31e80b7a
3 changed files with 9 additions and 5 deletions

View file

@ -9,6 +9,7 @@ import (
"github.com/deluan/navidrome/log" "github.com/deluan/navidrome/log"
"github.com/deluan/navidrome/model" "github.com/deluan/navidrome/model"
"github.com/deluan/rest" "github.com/deluan/rest"
"github.com/dhowden/tag/mbz"
) )
type albumRepository struct { type albumRepository struct {
@ -36,7 +37,7 @@ func (r *albumRepository) Put(a *model.Album) error {
if err != nil { if err != nil {
return err return err
} }
return r.index(a.ID, a.Name) return r.index(a.ID, a.Name, a.Artist, mbz.AlbumArtist)
} }
func (r *albumRepository) selectAlbum(options ...model.QueryOptions) SelectBuilder { func (r *albumRepository) selectAlbum(options ...model.QueryOptions) SelectBuilder {

View file

@ -41,7 +41,7 @@ func (r mediaFileRepository) Put(m *model.MediaFile) error {
if err != nil { if err != nil {
return err return err
} }
return r.index(m.ID, m.Title) return r.index(m.ID, m.Title, m.Album, m.Artist, m.AlbumArtist)
} }
func (r mediaFileRepository) selectMediaFile(options ...model.QueryOptions) SelectBuilder { func (r mediaFileRepository) selectMediaFile(options ...model.QueryOptions) SelectBuilder {

View file

@ -10,13 +10,16 @@ import (
const searchTable = "search" const searchTable = "search"
func (r sqlRepository) index(id string, text string) error { func (r sqlRepository) index(id string, text ...string) error {
sanitizedText := strings.TrimSpace(sanitize.Accents(strings.ToLower(text))) sanitizedText := strings.Builder{}
for _, txt := range text {
sanitizedText.WriteString(strings.TrimSpace(sanitize.Accents(strings.ToLower(txt))) + " ")
}
values := map[string]interface{}{ values := map[string]interface{}{
"id": id, "id": id,
"item_type": r.tableName, "item_type": r.tableName,
"full_text": sanitizedText, "full_text": strings.TrimSpace(sanitizedText.String()),
} }
update := Update(searchTable).Where(Eq{"id": id}).SetMap(values) update := Update(searchTable).Where(Eq{"id": id}).SetMap(values)
count, err := r.executeSQL(update) count, err := r.executeSQL(update)