diff --git a/bleve_indexer_test.go b/bleve_indexer_test.go index a7e1b7b..590aba9 100644 --- a/bleve_indexer_test.go +++ b/bleve_indexer_test.go @@ -21,9 +21,11 @@ func (s *BleveIndexerSuite) SetUpSuite(c *C) { start := time.Now() s.i, err = bleve.New(filepath.Join(c.MkDir(), "satbd-test.bar.satellite"), buildAlbumMapping()) c.Assert(err, IsNil) + batch := s.i.NewBatch() for _, a := range albumsDataTest { - c.Assert(s.i.Index(AlbumIDString(a.ID), &a), IsNil) + c.Assert(batch.Index(AlbumIDString(a.ID), &a), IsNil) } + c.Assert(s.i.Batch(batch), IsNil) log.Printf("Indexing took %s", time.Since(start)) } diff --git a/main.go b/main.go index 23f6055..fc1c0f9 100644 --- a/main.go +++ b/main.go @@ -57,13 +57,14 @@ func newAppData(opts Options) (*appData, error) { res := &appData{ opts: opts, - errors: make(chan error, 10), + errors: make(chan error), } blevePath := filepath.Join(basepath, "index") res.index, err = bleve.Open(blevePath) if err == bleve.ErrorIndexPathDoesNotExist { + log.Printf("Creating a new index in %s", blevePath) res.index, err = bleve.New(blevePath, buildAlbumMapping()) if err != nil { return nil, err @@ -151,8 +152,8 @@ func (a *appData) readCsv(stopChan <-chan struct{}, func (a *appData) submitBatchToIndex(batch *bleve.Batch) { s := batch.Size() log.Printf("[INDEX] start indexing of %d albums", s) - err := a.index.Batch(batch) start := time.Now() + err := a.index.Batch(batch) if err != nil { a.errors <- fmt.Errorf("[INDEX] batch indexing failed: %s", err) return @@ -181,12 +182,13 @@ func (a *appData) indexAlbum(stopChan <-chan struct{}, break } } - err := batch.Index(AlbumIDString(album.ID), a) + err := batch.Index(AlbumIDString(album.ID), album) if err != nil { a.errors <- fmt.Errorf("[INDEX] could not batch indexion of %s: %s", album, err) break + } else { + count++ } - count++ if count%a.opts.BatchSize == 0 { a.submitBatchToIndex(batch) batch = a.index.NewBatch() @@ -196,7 +198,7 @@ func (a *appData) indexAlbum(stopChan <-chan struct{}, albumToReIndex = nil break } - err := a.index.Index(AlbumIDString(album.ID), a) + err := a.index.Index(AlbumIDString(album.ID), album) if err != nil { a.errors <- fmt.Errorf("[INDEX] re-indexing %s failed: %s", album, err) } @@ -215,6 +217,7 @@ func (a *appData) indexAlbum(stopChan <-chan struct{}, } func (a *appData) cacheAlbumDescription(getAlbum <-chan *Album, toIndex chan<- *Album) { + defer close(toIndex) nbAlbums := 0 for album := range getAlbum { nbAlbums++ @@ -323,7 +326,7 @@ func (a *appData) updateCache(stopChan <-chan struct{}, periode time.Duration, c func (a *appData) logErrors() { for e := range a.errors { - log.Printf("%s", e) + log.Printf("[errors] ]%s", e) } } diff --git a/router.go b/router.go index c55e222..77e7868 100644 --- a/router.go +++ b/router.go @@ -34,7 +34,6 @@ func (a *appData) buildRouter() http.Handler { bleve_http.RegisterIndexName("album", a.index) searchHandler := bleve_http.NewSearchHandler("album") - router.POST("/api/search", narco.EndChain(ch, narco.HandlerFunc(func(_ context.Context, w http.ResponseWriter, req *http.Request, _ httprouter.Params) { searchHandler.ServeHTTP(w, req) diff --git a/static/index.html b/static/index.html index 493185e..40a7f02 100644 --- a/static/index.html +++ b/static/index.html @@ -38,9 +38,9 @@
  • Par Collection
  • Par Auteurs
  • -