Searching is fully working

This commit is contained in:
Deluan 2016-03-11 10:03:33 -05:00
parent 32f69c4a74
commit a918dc5a14
3 changed files with 42 additions and 31 deletions

View File

@ -46,6 +46,11 @@ type MusicFolders struct {
type Artist struct { type Artist struct {
Id string `xml:"id,attr" json:"id"` Id string `xml:"id,attr" json:"id"`
Name string `xml:"name,attr" json:"name"` Name string `xml:"name,attr" json:"name"`
/*
<xs:attribute name="starred" type="xs:dateTime" use="optional"/> <!-- Added in 1.10.1 -->
<xs:attribute name="userRating" type="sub:UserRating" use="optional"/> <!-- Added in 1.13.0 -->
<xs:attribute name="averageRating" type="sub:AverageRating" use="optional"/> <!-- Added in 1.13.0 -->
*/
} }
type Index struct { type Index struct {

View File

@ -21,38 +21,38 @@ func (c *SearchingController) Search2() {
query := c.RequiredParamString("query", "Parameter query required") query := c.RequiredParamString("query", "Parameter query required")
artistCount := c.ParamInt("artistCount", 20) artistCount := c.ParamInt("artistCount", 20)
artistOffset := c.ParamInt("artistOffset", 0) artistOffset := c.ParamInt("artistOffset", 0)
//albumCount := c.ParamInt("albumCount", 20) albumCount := c.ParamInt("albumCount", 20)
//albumOffset := c.ParamInt("albumOffset", 0) albumOffset := c.ParamInt("albumOffset", 0)
//songCount := c.ParamInt("songCount", 20) songCount := c.ParamInt("songCount", 20)
//songOffset := c.ParamInt("songOffset", 0) songOffset := c.ParamInt("songOffset", 0)
as, err := c.search.SearchArtist(query, artistOffset, artistCount) as, err := c.search.SearchArtist(query, artistOffset, artistCount)
if err != nil { if err != nil {
beego.Error("Error searching for Artists:", err) beego.Error("Error searching for Artists:", err)
} }
//als, err := c.search.SearchAlbum(query, albumOffset, albumCount) als, err := c.search.SearchAlbum(query, albumOffset, albumCount)
//if err != nil { if err != nil {
// beego.Error("Error searching for Albums:", err) beego.Error("Error searching for Albums:", err)
//} }
//mfs, err := c.search.SearchSong(query, songOffset, songCount) mfs, err := c.search.SearchSong(query, songOffset, songCount)
//if err != nil { if err != nil {
// beego.Error("Error searching for MediaFiles:", err) beego.Error("Error searching for MediaFiles:", err)
//} }
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, a := range *as { for i, e := range *as {
searchResult2.Artist[i] = responses.Artist{Id: a.Id, Name: a.Title} searchResult2.Artist[i] = responses.Artist{Id: e.Id, Name: e.Title}
}
searchResult2.Album = make([]responses.Child, len(*als))
for i, e := range *als {
searchResult2.Album[i] = c.ToChild(e)
}
searchResult2.Song = make([]responses.Child, len(*mfs))
for i, e := range *mfs {
searchResult2.Song[i] = c.ToChild(e)
} }
//searchResult2.Album = make([]responses.Child, len(*as))
//for i, a := range *as {
// searchResult2.Album[i] = responses.Child{Id: a.Id, Name: a.Name}
//}
//searchResult2.Artist = make([]responses.Artist, len(*as))
//for i, a := range *as {
// searchResult2.Artist[i] = responses.Artist{Id: a.Id, Name: a.Name}
//}
response.SearchResult2 = searchResult2 response.SearchResult2 = searchResult2
c.SendResponse(response) c.SendResponse(response)
} }

View File

@ -62,12 +62,14 @@ func (s search) IndexMediaFile(mf *domain.MediaFile) error {
} }
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 = strings.TrimSuffix(q, "*") q = strings.ToLower(strings.TrimSuffix(q, "*"))
resp, err := s.sArtist.Search(q) min := offset
max := min + size - 1
resp, err := s.sArtist.Search(q, min, max)
if err != nil { if err != nil {
return nil, nil return nil, nil
} }
res := make(Results, 0, len(resp)) res := make(Results, len(resp))
for i, id := range resp { for i, id := range resp {
a, err := s.artistRepo.Get(id) a, err := s.artistRepo.Get(id)
if err != nil { if err != nil {
@ -79,12 +81,14 @@ func (s search) SearchArtist(q string, offset int, size int) (*Results, error) {
} }
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 = strings.TrimSuffix(q, "*") q = strings.ToLower(strings.TrimSuffix(q, "*"))
resp, err := s.sAlbum.Search(q) min := offset
max := min + size - 1
resp, err := s.sAlbum.Search(q, min, max)
if err != nil { if err != nil {
return nil, nil return nil, nil
} }
res := make(Results, 0, len(resp)) res := make(Results, len(resp))
for i, id := range resp { for i, id := range resp {
al, err := s.albumRepo.Get(id) al, err := s.albumRepo.Get(id)
if err != nil { if err != nil {
@ -96,12 +100,14 @@ func (s search) SearchAlbum(q string, offset int, size int) (*Results, error) {
} }
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 = strings.TrimSuffix(q, "*") q = strings.ToLower(strings.TrimSuffix(q, "*"))
resp, err := s.sSong.Search(q) min := offset
max := min + size - 1
resp, err := s.sSong.Search(q, min, max)
if err != nil { if err != nil {
return nil, nil return nil, nil
} }
res := make(Results, 0, len(resp)) res := make(Results, len(resp))
for i, id := range resp { for i, id := range resp {
mf, err := s.mfileRepo.Get(id) mf, err := s.mfileRepo.Get(id)
if err != nil { if err != nil {