photoprism/internal/commands/index.go

51 lines
1,017 B
Go
Raw Normal View History

package commands
import (
"context"
"time"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/photoprism"
2019-05-02 14:10:05 +02:00
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
// Re-indexes all photos in originals directory (photo library)
var IndexCommand = cli.Command{
Name: "index",
Usage: "Re-indexes all originals",
Action: indexAction,
}
func indexAction(ctx *cli.Context) error {
start := time.Now()
conf := config.NewConfig(ctx)
if err := conf.CreateDirectories(); err != nil {
return err
}
cctx, cancel := context.WithCancel(context.Background())
defer cancel()
if err := conf.Init(cctx); err != nil {
return err
}
conf.MigrateDb()
log.Infof("indexing photos in %s", conf.OriginalsPath())
tensorFlow := photoprism.NewTensorFlow(conf)
indexer := photoprism.NewIndexer(conf, tensorFlow)
2019-05-02 14:10:05 +02:00
files := indexer.IndexAll()
elapsed := time.Since(start)
log.Infof("indexed %d files in %s", len(files), elapsed)
2019-06-04 00:22:25 +02:00
conf.Shutdown()
2019-06-04 00:22:25 +02:00
return nil
}