|
|
@ -2,7 +2,6 @@ package core
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"path/filepath"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
@ -11,7 +10,6 @@ import (
|
|
|
|
"github.com/mickael-menu/zk/internal/util/errors"
|
|
|
|
"github.com/mickael-menu/zk/internal/util/errors"
|
|
|
|
"github.com/mickael-menu/zk/internal/util/opt"
|
|
|
|
"github.com/mickael-menu/zk/internal/util/opt"
|
|
|
|
"github.com/mickael-menu/zk/internal/util/paths"
|
|
|
|
"github.com/mickael-menu/zk/internal/util/paths"
|
|
|
|
"github.com/schollz/progressbar/v3"
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Notebook handles queries and commands performed on an opened notebook.
|
|
|
|
// Notebook handles queries and commands performed on an opened notebook.
|
|
|
@ -62,13 +60,11 @@ type NotebookFactory func(path string, config Config) (*Notebook, error)
|
|
|
|
|
|
|
|
|
|
|
|
// Index indexes the content of the notebook to be searchable.
|
|
|
|
// Index indexes the content of the notebook to be searchable.
|
|
|
|
func (n *Notebook) Index(opts NoteIndexOpts) (stats NoteIndexingStats, err error) {
|
|
|
|
func (n *Notebook) Index(opts NoteIndexOpts) (stats NoteIndexingStats, err error) {
|
|
|
|
// FIXME: Move out of Core
|
|
|
|
return n.IndexWithCallback(opts, func(change paths.DiffChange) {})
|
|
|
|
bar := progressbar.NewOptions(-1,
|
|
|
|
}
|
|
|
|
progressbar.OptionSetWriter(os.Stderr),
|
|
|
|
|
|
|
|
progressbar.OptionThrottle(100*time.Millisecond),
|
|
|
|
|
|
|
|
progressbar.OptionSpinnerType(14),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Index indexes the content of the notebook to be searchable.
|
|
|
|
|
|
|
|
func (n *Notebook) IndexWithCallback(opts NoteIndexOpts, callback func(change paths.DiffChange)) (stats NoteIndexingStats, err error) {
|
|
|
|
err = n.index.Commit(func(index NoteIndex) error {
|
|
|
|
err = n.index.Commit(func(index NoteIndex) error {
|
|
|
|
task := indexTask{
|
|
|
|
task := indexTask{
|
|
|
|
path: n.Path,
|
|
|
|
path: n.Path,
|
|
|
@ -79,14 +75,10 @@ func (n *Notebook) Index(opts NoteIndexOpts) (stats NoteIndexingStats, err error
|
|
|
|
parser: n,
|
|
|
|
parser: n,
|
|
|
|
logger: n.logger,
|
|
|
|
logger: n.logger,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stats, err = task.execute(func(change paths.DiffChange) {
|
|
|
|
stats, err = task.execute(callback)
|
|
|
|
bar.Add(1)
|
|
|
|
|
|
|
|
bar.Describe(change.String())
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
bar.Clear()
|
|
|
|
|
|
|
|
err = errors.Wrap(err, "indexing")
|
|
|
|
err = errors.Wrap(err, "indexing")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|