use unidecoded string when searching
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
type Artist struct {
|
||||
IDBase
|
||||
Name string `gorm:"not null; unique_index"`
|
||||
NameUDec string `sql:"default: null"`
|
||||
Albums []*Album `gorm:"foreignkey:TagArtistID"`
|
||||
AlbumCount int `sql:"-"`
|
||||
}
|
||||
@@ -19,6 +20,7 @@ type Track struct {
|
||||
IDBase
|
||||
CrudBase
|
||||
Filename string `gorm:"not null; unique_index:idx_folder_filename" sql:"default: null"`
|
||||
FilenameUDec string `sql:"default: null"`
|
||||
Album *Album
|
||||
AlbumID int `gorm:"not null; unique_index:idx_folder_filename" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
|
||||
Artist *Artist
|
||||
@@ -27,6 +29,7 @@ type Track struct {
|
||||
Length int `sql:"default: null"`
|
||||
Bitrate int `sql:"default: null"`
|
||||
TagTitle string `sql:"default: null"`
|
||||
TagTitleUDec string `sql:"default: null"`
|
||||
TagTrackArtist string `sql:"default: null"`
|
||||
TagTrackNumber int `sql:"default: null"`
|
||||
TagDiscNumber int `sql:"default: null"`
|
||||
@@ -75,12 +78,14 @@ type Album struct {
|
||||
CrudBase
|
||||
LeftPath string `gorm:"unique_index:idx_left_path_right_path"`
|
||||
RightPath string `gorm:"not null; unique_index:idx_left_path_right_path" sql:"default: null"`
|
||||
RightPathUDec string `sql:"default: null"`
|
||||
Parent *Album
|
||||
ParentID int `sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
|
||||
Cover string `sql:"default: null"`
|
||||
TagArtist *Artist
|
||||
TagArtistID int `gorm:"index" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
|
||||
TagTitle string `gorm:"index" sql:"default: null"`
|
||||
TagTitleUDec string `sql:"default: null"`
|
||||
TagYear int `sql:"default: null"`
|
||||
Tracks []*Track
|
||||
ChildCount int `sql:"-"`
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/karrick/godirwalk"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rainycape/unidecode"
|
||||
|
||||
"github.com/sentriz/gonic/mime"
|
||||
"github.com/sentriz/gonic/model"
|
||||
@@ -37,6 +38,10 @@ var coverFilenames = map[string]struct{}{
|
||||
"front.jpeg": {},
|
||||
}
|
||||
|
||||
func decoded(in string) string {
|
||||
return unidecode.Unidecode(in)
|
||||
}
|
||||
|
||||
type Scanner struct {
|
||||
db, tx *gorm.DB
|
||||
musicPath string
|
||||
@@ -241,6 +246,7 @@ func (s *Scanner) handleFolder(it *item) error {
|
||||
}
|
||||
folder.LeftPath = it.directory
|
||||
folder.RightPath = it.filename
|
||||
folder.RightPathUDec = decoded(it.filename)
|
||||
s.tx.Save(folder)
|
||||
folder.ReceivedPaths = true
|
||||
return nil
|
||||
@@ -264,6 +270,7 @@ func (s *Scanner) handleTrack(it *item) error {
|
||||
return nil
|
||||
}
|
||||
track.Filename = it.filename
|
||||
track.FilenameUDec = decoded(it.filename)
|
||||
track.Size = int(it.stat.Size())
|
||||
track.AlbumID = s.curFolderID()
|
||||
trTags, err := tags.New(it.fullPath)
|
||||
@@ -276,6 +283,7 @@ func (s *Scanner) handleTrack(it *item) error {
|
||||
return nil
|
||||
}
|
||||
track.TagTitle = trTags.Title()
|
||||
track.TagTitleUDec = decoded(trTags.Title())
|
||||
track.TagTrackArtist = trTags.Artist()
|
||||
track.TagTrackNumber = trTags.TrackNumber()
|
||||
track.TagDiscNumber = trTags.DiscNumber()
|
||||
@@ -299,6 +307,7 @@ func (s *Scanner) handleTrack(it *item) error {
|
||||
Error
|
||||
if gorm.IsRecordNotFoundError(err) {
|
||||
artist.Name = artistName
|
||||
artist.NameUDec = decoded(artistName)
|
||||
s.tx.Save(artist)
|
||||
}
|
||||
track.ArtistID = artist.ID
|
||||
@@ -313,6 +322,7 @@ func (s *Scanner) handleTrack(it *item) error {
|
||||
return nil
|
||||
}
|
||||
folder.TagTitle = trTags.Album()
|
||||
folder.TagTitleUDec = decoded(trTags.Album())
|
||||
folder.TagYear = trTags.Year()
|
||||
folder.TagArtistID = artist.ID
|
||||
folder.ReceivedTags = true
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
|
||||
func (c *Controller) GetIndexes(w http.ResponseWriter, r *http.Request) {
|
||||
var folders []*model.Album
|
||||
|
||||
c.DB.
|
||||
Select("*, count(sub.id) as child_count").
|
||||
Joins(`
|
||||
@@ -33,7 +32,7 @@ func (c *Controller) GetIndexes(w http.ResponseWriter, r *http.Request) {
|
||||
indexMap := make(map[string]*subsonic.Index)
|
||||
indexes := []*subsonic.Index{}
|
||||
for _, folder := range folders {
|
||||
i := indexOf(folder.RightPath[0])
|
||||
i := indexOf(folder.RightPathUDec[0])
|
||||
index, ok := indexMap[i]
|
||||
if !ok {
|
||||
index = &subsonic.Index{
|
||||
@@ -167,7 +166,7 @@ func (c *Controller) SearchTwo(w http.ResponseWriter, r *http.Request) {
|
||||
// search "artists"
|
||||
var artists []*model.Album
|
||||
c.DB.
|
||||
Where("parent_id = 1 AND right_path LIKE ?", query).
|
||||
Where("parent_id = 1 AND right_path_u_dec LIKE ?", query).
|
||||
Offset(getIntParamOr(r, "artistOffset", 0)).
|
||||
Limit(getIntParamOr(r, "artistCount", 20)).
|
||||
Find(&artists)
|
||||
@@ -179,7 +178,7 @@ func (c *Controller) SearchTwo(w http.ResponseWriter, r *http.Request) {
|
||||
// search "albums"
|
||||
var albums []*model.Album
|
||||
c.DB.
|
||||
Where("tag_artist_id IS NOT NULL AND right_path LIKE ?", query).
|
||||
Where("tag_artist_id IS NOT NULL AND right_path_u_dec LIKE ?", query).
|
||||
Offset(getIntParamOr(r, "albumOffset", 0)).
|
||||
Limit(getIntParamOr(r, "albumCount", 20)).
|
||||
Find(&albums)
|
||||
@@ -191,7 +190,7 @@ func (c *Controller) SearchTwo(w http.ResponseWriter, r *http.Request) {
|
||||
var tracks []*model.Track
|
||||
c.DB.
|
||||
Preload("Album").
|
||||
Where("filename LIKE ?", query).
|
||||
Where("filename_u_dec LIKE ?", query).
|
||||
Offset(getIntParamOr(r, "songOffset", 0)).
|
||||
Limit(getIntParamOr(r, "songCount", 20)).
|
||||
Find(&tracks)
|
||||
|
||||
@@ -25,7 +25,7 @@ func (c *Controller) GetArtists(w http.ResponseWriter, r *http.Request) {
|
||||
indexMap := make(map[string]*subsonic.Index)
|
||||
indexes := &subsonic.Artists{}
|
||||
for _, artist := range artists {
|
||||
i := indexOf(artist.Name[0])
|
||||
i := indexOf(artist.NameUDec[0])
|
||||
index, ok := indexMap[i]
|
||||
if !ok {
|
||||
index = &subsonic.Index{
|
||||
@@ -167,7 +167,7 @@ func (c *Controller) SearchThree(w http.ResponseWriter, r *http.Request) {
|
||||
// search "artists"
|
||||
var artists []*model.Artist
|
||||
c.DB.
|
||||
Where("name LIKE ?", query).
|
||||
Where("name_u_dec LIKE ?", query).
|
||||
Offset(getIntParamOr(r, "artistOffset", 0)).
|
||||
Limit(getIntParamOr(r, "artistCount", 20)).
|
||||
Find(&artists)
|
||||
@@ -180,7 +180,7 @@ func (c *Controller) SearchThree(w http.ResponseWriter, r *http.Request) {
|
||||
var albums []*model.Album
|
||||
c.DB.
|
||||
Preload("TagArtist").
|
||||
Where("tag_title LIKE ?", query).
|
||||
Where("tag_title_u_dec LIKE ?", query).
|
||||
Offset(getIntParamOr(r, "albumOffset", 0)).
|
||||
Limit(getIntParamOr(r, "albumCount", 20)).
|
||||
Find(&albums)
|
||||
@@ -193,7 +193,7 @@ func (c *Controller) SearchThree(w http.ResponseWriter, r *http.Request) {
|
||||
var tracks []*model.Track
|
||||
c.DB.
|
||||
Preload("Album").
|
||||
Where("tag_title LIKE ?", query).
|
||||
Where("tag_title_u_dec LIKE ?", query).
|
||||
Offset(getIntParamOr(r, "songOffset", 0)).
|
||||
Limit(getIntParamOr(r, "songCount", 20)).
|
||||
Find(&tracks)
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"unicode"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/rainycape/unidecode"
|
||||
|
||||
"github.com/sentriz/gonic/model"
|
||||
"github.com/sentriz/gonic/scanner"
|
||||
@@ -21,11 +20,10 @@ import (
|
||||
|
||||
func indexOf(in byte) string {
|
||||
lower := strings.ToLower(string(in))
|
||||
decode := unidecode.Unidecode(lower)
|
||||
if !unicode.IsLetter(rune(decode[0])) {
|
||||
if !unicode.IsLetter(rune(lower[0])) {
|
||||
return "#"
|
||||
}
|
||||
return decode
|
||||
return lower
|
||||
}
|
||||
|
||||
func (c *Controller) Stream(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user