mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-16 20:12:22 +03:00
Searching is fully working
This commit is contained in:
parent
32f69c4a74
commit
a918dc5a14
@ -46,6 +46,11 @@ type MusicFolders struct {
|
||||
type Artist struct {
|
||||
Id string `xml:"id,attr" json:"id"`
|
||||
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 {
|
||||
|
@ -21,38 +21,38 @@ func (c *SearchingController) Search2() {
|
||||
query := c.RequiredParamString("query", "Parameter query required")
|
||||
artistCount := c.ParamInt("artistCount", 20)
|
||||
artistOffset := c.ParamInt("artistOffset", 0)
|
||||
//albumCount := c.ParamInt("albumCount", 20)
|
||||
//albumOffset := c.ParamInt("albumOffset", 0)
|
||||
//songCount := c.ParamInt("songCount", 20)
|
||||
//songOffset := c.ParamInt("songOffset", 0)
|
||||
albumCount := c.ParamInt("albumCount", 20)
|
||||
albumOffset := c.ParamInt("albumOffset", 0)
|
||||
songCount := c.ParamInt("songCount", 20)
|
||||
songOffset := c.ParamInt("songOffset", 0)
|
||||
|
||||
as, err := c.search.SearchArtist(query, artistOffset, artistCount)
|
||||
if err != nil {
|
||||
beego.Error("Error searching for Artists:", err)
|
||||
}
|
||||
//als, err := c.search.SearchAlbum(query, albumOffset, albumCount)
|
||||
//if err != nil {
|
||||
// beego.Error("Error searching for Albums:", err)
|
||||
//}
|
||||
//mfs, err := c.search.SearchSong(query, songOffset, songCount)
|
||||
//if err != nil {
|
||||
// beego.Error("Error searching for MediaFiles:", err)
|
||||
//}
|
||||
als, err := c.search.SearchAlbum(query, albumOffset, albumCount)
|
||||
if err != nil {
|
||||
beego.Error("Error searching for Albums:", err)
|
||||
}
|
||||
mfs, err := c.search.SearchSong(query, songOffset, songCount)
|
||||
if err != nil {
|
||||
beego.Error("Error searching for MediaFiles:", err)
|
||||
}
|
||||
|
||||
response := c.NewEmpty()
|
||||
searchResult2 := &responses.SearchResult2{}
|
||||
searchResult2.Artist = make([]responses.Artist, len(*as))
|
||||
for i, a := range *as {
|
||||
searchResult2.Artist[i] = responses.Artist{Id: a.Id, Name: a.Title}
|
||||
for i, e := range *as {
|
||||
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
|
||||
c.SendResponse(response)
|
||||
}
|
@ -62,12 +62,14 @@ func (s search) IndexMediaFile(mf *domain.MediaFile) error {
|
||||
}
|
||||
|
||||
func (s search) SearchArtist(q string, offset int, size int) (*Results, error) {
|
||||
q = strings.TrimSuffix(q, "*")
|
||||
resp, err := s.sArtist.Search(q)
|
||||
q = strings.ToLower(strings.TrimSuffix(q, "*"))
|
||||
min := offset
|
||||
max := min + size - 1
|
||||
resp, err := s.sArtist.Search(q, min, max)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
res := make(Results, 0, len(resp))
|
||||
res := make(Results, len(resp))
|
||||
for i, id := range resp {
|
||||
a, err := s.artistRepo.Get(id)
|
||||
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) {
|
||||
q = strings.TrimSuffix(q, "*")
|
||||
resp, err := s.sAlbum.Search(q)
|
||||
q = strings.ToLower(strings.TrimSuffix(q, "*"))
|
||||
min := offset
|
||||
max := min + size - 1
|
||||
resp, err := s.sAlbum.Search(q, min, max)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
res := make(Results, 0, len(resp))
|
||||
res := make(Results, len(resp))
|
||||
for i, id := range resp {
|
||||
al, err := s.albumRepo.Get(id)
|
||||
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) {
|
||||
q = strings.TrimSuffix(q, "*")
|
||||
resp, err := s.sSong.Search(q)
|
||||
q = strings.ToLower(strings.TrimSuffix(q, "*"))
|
||||
min := offset
|
||||
max := min + size - 1
|
||||
resp, err := s.sSong.Search(q, min, max)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
res := make(Results, 0, len(resp))
|
||||
res := make(Results, len(resp))
|
||||
for i, id := range resp {
|
||||
mf, err := s.mfileRepo.Get(id)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user