Using slices for Results, instead of pointers of slices
This commit is contained in:
+6
-6
@@ -40,16 +40,16 @@ func (c *SearchingController) Search2() {
|
|||||||
|
|
||||||
response := c.NewEmpty()
|
response := c.NewEmpty()
|
||||||
searchResult2 := &responses.SearchResult2{}
|
searchResult2 := &responses.SearchResult2{}
|
||||||
searchResult2.Artist = make([]responses.Artist, len(*as))
|
searchResult2.Artist = make([]responses.Artist, len(as))
|
||||||
for i, e := range *as {
|
for i, e := range as {
|
||||||
searchResult2.Artist[i] = responses.Artist{Id: e.Id, Name: e.Title}
|
searchResult2.Artist[i] = responses.Artist{Id: e.Id, Name: e.Title}
|
||||||
}
|
}
|
||||||
searchResult2.Album = make([]responses.Child, len(*als))
|
searchResult2.Album = make([]responses.Child, len(als))
|
||||||
for i, e := range *als {
|
for i, e := range als {
|
||||||
searchResult2.Album[i] = c.ToChild(e)
|
searchResult2.Album[i] = c.ToChild(e)
|
||||||
}
|
}
|
||||||
searchResult2.Song = make([]responses.Child, len(*mfs))
|
searchResult2.Song = make([]responses.Child, len(mfs))
|
||||||
for i, e := range *mfs {
|
for i, e := range mfs {
|
||||||
searchResult2.Song[i] = c.ToChild(e)
|
searchResult2.Song[i] = c.ToChild(e)
|
||||||
}
|
}
|
||||||
response.SearchResult2 = searchResult2
|
response.SearchResult2 = searchResult2
|
||||||
|
|||||||
+9
-9
@@ -17,9 +17,9 @@ type Search interface {
|
|||||||
IndexAlbum(al *domain.Album) error
|
IndexAlbum(al *domain.Album) error
|
||||||
IndexMediaFile(mf *domain.MediaFile) error
|
IndexMediaFile(mf *domain.MediaFile) error
|
||||||
|
|
||||||
SearchArtist(q string, offset int, size int) (*Results, error)
|
SearchArtist(q string, offset int, size int) (Results, error)
|
||||||
SearchAlbum(q string, offset int, size int) (*Results, error)
|
SearchAlbum(q string, offset int, size int) (Results, error)
|
||||||
SearchSong(q string, offset int, size int) (*Results, error)
|
SearchSong(q string, offset int, size int) (Results, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type search struct {
|
type search struct {
|
||||||
@@ -63,7 +63,7 @@ func (s search) IndexMediaFile(mf *domain.MediaFile) error {
|
|||||||
return s.idxSong.Index(mf.Id, sanitize.Accents(strings.ToLower(mf.Title)))
|
return s.idxSong.Index(mf.Id, sanitize.Accents(strings.ToLower(mf.Title)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s search) SearchArtist(q string, offset int, size int) (*Results, error) {
|
func (s search) SearchArtist(q string, offset int, size int) (Results, error) {
|
||||||
q = sanitize.Accents(strings.ToLower(strings.TrimSuffix(q, "*")))
|
q = sanitize.Accents(strings.ToLower(strings.TrimSuffix(q, "*")))
|
||||||
min := offset
|
min := offset
|
||||||
max := min + size - 1
|
max := min + size - 1
|
||||||
@@ -81,10 +81,10 @@ func (s search) SearchArtist(q string, offset int, size int) (*Results, error) {
|
|||||||
res = append(res, Entry{Id: a.Id, Title: a.Name, IsDir: true})
|
res = append(res, Entry{Id: a.Id, Title: a.Name, IsDir: true})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s search) SearchAlbum(q string, offset int, size int) (*Results, error) {
|
func (s search) SearchAlbum(q string, offset int, size int) (Results, error) {
|
||||||
q = sanitize.Accents(strings.ToLower(strings.TrimSuffix(q, "*")))
|
q = sanitize.Accents(strings.ToLower(strings.TrimSuffix(q, "*")))
|
||||||
min := offset
|
min := offset
|
||||||
max := min + size - 1
|
max := min + size - 1
|
||||||
@@ -102,10 +102,10 @@ func (s search) SearchAlbum(q string, offset int, size int) (*Results, error) {
|
|||||||
res = append(res, FromAlbum(al))
|
res = append(res, FromAlbum(al))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s search) SearchSong(q string, offset int, size int) (*Results, error) {
|
func (s search) SearchSong(q string, offset int, size int) (Results, error) {
|
||||||
q = sanitize.Accents(strings.ToLower(strings.TrimSuffix(q, "*")))
|
q = sanitize.Accents(strings.ToLower(strings.TrimSuffix(q, "*")))
|
||||||
min := offset
|
min := offset
|
||||||
max := min + size - 1
|
max := min + size - 1
|
||||||
@@ -123,7 +123,7 @@ func (s search) SearchSong(q string, offset int, size int) (*Results, error) {
|
|||||||
res = append(res, FromMediaFile(mf))
|
res = append(res, FromMediaFile(mf))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func criticalError(kind, id string, err error) bool {
|
func criticalError(kind, id string, err error) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user