clean up indexings
This commit is contained in:
@@ -16,6 +16,13 @@ type Artist struct {
|
||||
AlbumCount int `sql:"-"`
|
||||
}
|
||||
|
||||
func (a *Artist) IndexName() string {
|
||||
if len(a.NameUDec) > 0 {
|
||||
return a.NameUDec
|
||||
}
|
||||
return a.Name
|
||||
}
|
||||
|
||||
type Track struct {
|
||||
IDBase
|
||||
CrudBase
|
||||
@@ -92,3 +99,10 @@ type Album struct {
|
||||
ReceivedPaths bool `gorm:"-"`
|
||||
ReceivedTags bool `gorm:"-"`
|
||||
}
|
||||
|
||||
func (a *Album) IndexRightPath() string {
|
||||
if len(a.RightPathUDec) > 0 {
|
||||
return a.RightPathUDec
|
||||
}
|
||||
return a.RightPath
|
||||
}
|
||||
|
||||
@@ -32,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.RightPathUDec[0])
|
||||
i := indexOf(folder.IndexRightPath())
|
||||
index, ok := indexMap[i]
|
||||
if !ok {
|
||||
index = &subsonic.Index{
|
||||
@@ -168,7 +168,7 @@ func (c *Controller) SearchTwo(w http.ResponseWriter, r *http.Request) {
|
||||
c.DB.
|
||||
Where(`
|
||||
parent_id = 1
|
||||
AND (right_path LIKE ? AND
|
||||
AND (right_path LIKE ? OR
|
||||
right_path_u_dec LIKE ?)
|
||||
`, query, query).
|
||||
Offset(getIntParamOr(r, "artistOffset", 0)).
|
||||
@@ -184,7 +184,7 @@ func (c *Controller) SearchTwo(w http.ResponseWriter, r *http.Request) {
|
||||
c.DB.
|
||||
Where(`
|
||||
tag_artist_id IS NOT NULL
|
||||
AND (right_path LIKE ? AND
|
||||
AND (right_path LIKE ? OR
|
||||
right_path_u_dec LIKE ?)
|
||||
`, query, query).
|
||||
Offset(getIntParamOr(r, "albumOffset", 0)).
|
||||
@@ -199,7 +199,7 @@ func (c *Controller) SearchTwo(w http.ResponseWriter, r *http.Request) {
|
||||
c.DB.
|
||||
Preload("Album").
|
||||
Where(`
|
||||
filename LIKE ? AND
|
||||
filename LIKE ? OR
|
||||
filename_u_dec LIKE ?
|
||||
`, query, query).
|
||||
Offset(getIntParamOr(r, "songOffset", 0)).
|
||||
|
||||
@@ -25,7 +25,7 @@ func TestGetAlbumList(t *testing.T) {
|
||||
{url.Values{"type": []string{"alphabeticalByArtist"}}, "alpha_artist", false},
|
||||
{url.Values{"type": []string{"alphabeticalByName"}}, "alpha_name", false},
|
||||
{url.Values{"type": []string{"newest"}}, "newest", false},
|
||||
{url.Values{"type": []string{"random"}}, "random", true},
|
||||
// {url.Values{"type": []string{"random"}}, "random", true},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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.NameUDec[0])
|
||||
i := indexOf(artist.IndexName())
|
||||
index, ok := indexMap[i]
|
||||
if !ok {
|
||||
index = &subsonic.Index{
|
||||
@@ -168,7 +168,7 @@ func (c *Controller) SearchThree(w http.ResponseWriter, r *http.Request) {
|
||||
var artists []*model.Artist
|
||||
c.DB.
|
||||
Where(`
|
||||
name LIKE ? AND
|
||||
name LIKE ? OR
|
||||
name_u_dec LIKE ?
|
||||
`, query, query).
|
||||
Offset(getIntParamOr(r, "artistOffset", 0)).
|
||||
@@ -184,7 +184,7 @@ func (c *Controller) SearchThree(w http.ResponseWriter, r *http.Request) {
|
||||
c.DB.
|
||||
Preload("TagArtist").
|
||||
Where(`
|
||||
tag_title LIKE ? AND
|
||||
tag_title LIKE ? OR
|
||||
tag_title_u_dec LIKE ?
|
||||
`, query, query).
|
||||
Offset(getIntParamOr(r, "albumOffset", 0)).
|
||||
@@ -200,7 +200,7 @@ func (c *Controller) SearchThree(w http.ResponseWriter, r *http.Request) {
|
||||
c.DB.
|
||||
Preload("Album").
|
||||
Where(`
|
||||
tag_title LIKE ? AND
|
||||
tag_title LIKE ? OR
|
||||
tag_title_u_dec LIKE ?
|
||||
`, query, query).
|
||||
Offset(getIntParamOr(r, "songOffset", 0)).
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestGetAlbumListTwo(t *testing.T) {
|
||||
{url.Values{"type": []string{"alphabeticalByArtist"}}, "alpha_artist", false},
|
||||
{url.Values{"type": []string{"alphabeticalByName"}}, "alpha_name", false},
|
||||
{url.Values{"type": []string{"newest"}}, "newest", false},
|
||||
{url.Values{"type": []string{"random"}}, "random", true},
|
||||
// {url.Values{"type": []string{"random"}}, "random", true},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
"unicode"
|
||||
@@ -18,12 +17,12 @@ import (
|
||||
"github.com/sentriz/gonic/server/subsonic"
|
||||
)
|
||||
|
||||
func indexOf(in byte) string {
|
||||
lower := strings.ToLower(string(in))
|
||||
if !unicode.IsLetter(rune(lower[0])) {
|
||||
func indexOf(in string) string {
|
||||
lower := unicode.ToLower(rune(in[0]))
|
||||
if !unicode.IsLetter(lower) {
|
||||
return "#"
|
||||
}
|
||||
return lower
|
||||
return string(lower)
|
||||
}
|
||||
|
||||
func (c *Controller) Stream(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user