Indexing everything

This commit is contained in:
Deluan
2016-03-10 23:24:30 -05:00
parent df957814a0
commit 4780b54f01
2 changed files with 25 additions and 4 deletions
+17 -4
View File
@@ -8,9 +8,10 @@ import (
)
type Search interface {
ClearAll() error
IndexArtist(ar *domain.Artist) error
//IndexAlbum(al domain.Album) error
//IndexMediaFile(mf domain.MediaFile) error
IndexAlbum(al *domain.Album) error
IndexMediaFile(mf *domain.MediaFile) error
}
type search struct {
@@ -24,6 +25,18 @@ func NewSearch(ar domain.ArtistRepository, alr domain.AlbumRepository, mr domain
return search{ar, alr, mr, idx}
}
func (s search) IndexArtist(ar *domain.Artist) error {
return s.indexer.Index(ar.Id, strings.ToLower(ar.Name))
func (s search) ClearAll() error {
return s.indexer.Clear()
}
func (s search) IndexArtist(ar *domain.Artist) error {
return s.indexer.Index("ar-"+ar.Id, strings.ToLower(ar.Name))
}
func (s search) IndexAlbum(al *domain.Album) error {
return s.indexer.Index("al-"+al.Id, strings.ToLower(al.Name))
}
func (s search) IndexMediaFile(mf *domain.MediaFile) error {
return s.indexer.Index("mf-"+mf.Id, strings.ToLower(mf.Title))
}
+8
View File
@@ -92,6 +92,8 @@ func (i *Importer) importLibrary() (err error) {
ars := make(domain.Artists, len(i.scanner.Artists()))
pls := make(domain.Playlists, len(i.scanner.Playlists()))
i.search.ClearAll()
beego.Debug("Saving updated data")
j := 0
for _, mf := range i.scanner.MediaFiles() {
@@ -103,6 +105,9 @@ func (i *Importer) importLibrary() (err error) {
if err := i.mfRepo.Put(mf); err != nil {
beego.Error(err)
}
if err := i.search.IndexMediaFile(mf); err != nil {
beego.Error("Error indexing artist:", err)
}
}
j = 0
@@ -115,6 +120,9 @@ func (i *Importer) importLibrary() (err error) {
if err := i.albumRepo.Put(al); err != nil {
beego.Error(err)
}
if err := i.search.IndexAlbum(al); err != nil {
beego.Error("Error indexing artist:", err)
}
}
j = 0