clean up indexings

This commit is contained in:
sentriz
2019-06-27 18:06:33 +01:00
parent c6d4ea5b90
commit 79eeca77ae
6 changed files with 28 additions and 15 deletions

View File

@@ -16,6 +16,13 @@ type Artist struct {
AlbumCount int `sql:"-"` AlbumCount int `sql:"-"`
} }
func (a *Artist) IndexName() string {
if len(a.NameUDec) > 0 {
return a.NameUDec
}
return a.Name
}
type Track struct { type Track struct {
IDBase IDBase
CrudBase CrudBase
@@ -92,3 +99,10 @@ type Album struct {
ReceivedPaths bool `gorm:"-"` ReceivedPaths bool `gorm:"-"`
ReceivedTags bool `gorm:"-"` ReceivedTags bool `gorm:"-"`
} }
func (a *Album) IndexRightPath() string {
if len(a.RightPathUDec) > 0 {
return a.RightPathUDec
}
return a.RightPath
}

View File

@@ -32,7 +32,7 @@ func (c *Controller) GetIndexes(w http.ResponseWriter, r *http.Request) {
indexMap := make(map[string]*subsonic.Index) indexMap := make(map[string]*subsonic.Index)
indexes := []*subsonic.Index{} indexes := []*subsonic.Index{}
for _, folder := range folders { for _, folder := range folders {
i := indexOf(folder.RightPathUDec[0]) i := indexOf(folder.IndexRightPath())
index, ok := indexMap[i] index, ok := indexMap[i]
if !ok { if !ok {
index = &subsonic.Index{ index = &subsonic.Index{
@@ -168,7 +168,7 @@ func (c *Controller) SearchTwo(w http.ResponseWriter, r *http.Request) {
c.DB. c.DB.
Where(` Where(`
parent_id = 1 parent_id = 1
AND (right_path LIKE ? AND AND (right_path LIKE ? OR
right_path_u_dec LIKE ?) right_path_u_dec LIKE ?)
`, query, query). `, query, query).
Offset(getIntParamOr(r, "artistOffset", 0)). Offset(getIntParamOr(r, "artistOffset", 0)).
@@ -184,7 +184,7 @@ func (c *Controller) SearchTwo(w http.ResponseWriter, r *http.Request) {
c.DB. c.DB.
Where(` Where(`
tag_artist_id IS NOT NULL tag_artist_id IS NOT NULL
AND (right_path LIKE ? AND AND (right_path LIKE ? OR
right_path_u_dec LIKE ?) right_path_u_dec LIKE ?)
`, query, query). `, query, query).
Offset(getIntParamOr(r, "albumOffset", 0)). Offset(getIntParamOr(r, "albumOffset", 0)).
@@ -199,7 +199,7 @@ func (c *Controller) SearchTwo(w http.ResponseWriter, r *http.Request) {
c.DB. c.DB.
Preload("Album"). Preload("Album").
Where(` Where(`
filename LIKE ? AND filename LIKE ? OR
filename_u_dec LIKE ? filename_u_dec LIKE ?
`, query, query). `, query, query).
Offset(getIntParamOr(r, "songOffset", 0)). Offset(getIntParamOr(r, "songOffset", 0)).

View File

@@ -25,7 +25,7 @@ func TestGetAlbumList(t *testing.T) {
{url.Values{"type": []string{"alphabeticalByArtist"}}, "alpha_artist", false}, {url.Values{"type": []string{"alphabeticalByArtist"}}, "alpha_artist", false},
{url.Values{"type": []string{"alphabeticalByName"}}, "alpha_name", false}, {url.Values{"type": []string{"alphabeticalByName"}}, "alpha_name", false},
{url.Values{"type": []string{"newest"}}, "newest", false}, {url.Values{"type": []string{"newest"}}, "newest", false},
{url.Values{"type": []string{"random"}}, "random", true}, // {url.Values{"type": []string{"random"}}, "random", true},
}) })
} }

View File

@@ -25,7 +25,7 @@ func (c *Controller) GetArtists(w http.ResponseWriter, r *http.Request) {
indexMap := make(map[string]*subsonic.Index) indexMap := make(map[string]*subsonic.Index)
indexes := &subsonic.Artists{} indexes := &subsonic.Artists{}
for _, artist := range artists { for _, artist := range artists {
i := indexOf(artist.NameUDec[0]) i := indexOf(artist.IndexName())
index, ok := indexMap[i] index, ok := indexMap[i]
if !ok { if !ok {
index = &subsonic.Index{ index = &subsonic.Index{
@@ -168,7 +168,7 @@ func (c *Controller) SearchThree(w http.ResponseWriter, r *http.Request) {
var artists []*model.Artist var artists []*model.Artist
c.DB. c.DB.
Where(` Where(`
name LIKE ? AND name LIKE ? OR
name_u_dec LIKE ? name_u_dec LIKE ?
`, query, query). `, query, query).
Offset(getIntParamOr(r, "artistOffset", 0)). Offset(getIntParamOr(r, "artistOffset", 0)).
@@ -184,7 +184,7 @@ func (c *Controller) SearchThree(w http.ResponseWriter, r *http.Request) {
c.DB. c.DB.
Preload("TagArtist"). Preload("TagArtist").
Where(` Where(`
tag_title LIKE ? AND tag_title LIKE ? OR
tag_title_u_dec LIKE ? tag_title_u_dec LIKE ?
`, query, query). `, query, query).
Offset(getIntParamOr(r, "albumOffset", 0)). Offset(getIntParamOr(r, "albumOffset", 0)).
@@ -200,7 +200,7 @@ func (c *Controller) SearchThree(w http.ResponseWriter, r *http.Request) {
c.DB. c.DB.
Preload("Album"). Preload("Album").
Where(` Where(`
tag_title LIKE ? AND tag_title LIKE ? OR
tag_title_u_dec LIKE ? tag_title_u_dec LIKE ?
`, query, query). `, query, query).
Offset(getIntParamOr(r, "songOffset", 0)). Offset(getIntParamOr(r, "songOffset", 0)).

View File

@@ -31,7 +31,7 @@ func TestGetAlbumListTwo(t *testing.T) {
{url.Values{"type": []string{"alphabeticalByArtist"}}, "alpha_artist", false}, {url.Values{"type": []string{"alphabeticalByArtist"}}, "alpha_artist", false},
{url.Values{"type": []string{"alphabeticalByName"}}, "alpha_name", false}, {url.Values{"type": []string{"alphabeticalByName"}}, "alpha_name", false},
{url.Values{"type": []string{"newest"}}, "newest", false}, {url.Values{"type": []string{"newest"}}, "newest", false},
{url.Values{"type": []string{"random"}}, "random", true}, // {url.Values{"type": []string{"random"}}, "random", true},
}) })
} }

View File

@@ -5,7 +5,6 @@ import (
"net/http" "net/http"
"os" "os"
"path" "path"
"strings"
"sync/atomic" "sync/atomic"
"time" "time"
"unicode" "unicode"
@@ -18,12 +17,12 @@ import (
"github.com/sentriz/gonic/server/subsonic" "github.com/sentriz/gonic/server/subsonic"
) )
func indexOf(in byte) string { func indexOf(in string) string {
lower := strings.ToLower(string(in)) lower := unicode.ToLower(rune(in[0]))
if !unicode.IsLetter(rune(lower[0])) { if !unicode.IsLetter(lower) {
return "#" return "#"
} }
return lower return string(lower)
} }
func (c *Controller) Stream(w http.ResponseWriter, r *http.Request) { func (c *Controller) Stream(w http.ResponseWriter, r *http.Request) {