From 786ff5cff8d6fdca6dd80bd0807619bdea5f0f51 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Fri, 19 Apr 2024 18:45:07 +0200 Subject: feat: Add spellfix check back for fts5 --- Makefile | 3 +-- cmd/ui/ui.go | 10 ++++++---- db/db.go | 15 +++++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index eb08518..a04902b 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,7 @@ buid: ext $(GO_BUILD) -o $(BIN) ./cmd/dict/main.go run: ext - $(GO_RUN) ./cmd/dict/main.go - + $(GO_RUN) ./cmd/dict/main.go ui import: ext $(GO_RUN) ./cmd/dict/main.go import diff --git a/cmd/ui/ui.go b/cmd/ui/ui.go index 82c0bc5..b5f2f2f 100644 --- a/cmd/ui/ui.go +++ b/cmd/ui/ui.go @@ -21,13 +21,13 @@ var UICommand = &cli.Command{ Usage: "interactive dictionary", Flags: []cli.Flag{ &cli.StringFlag{ - Name: "filename", + Name: "database", Value: "main.dict", Usage: "Dictionary database location", }, }, Action: func(cCtx *cli.Context) error { - name := cCtx.String("lang") + name := cCtx.String("database") return Run(context.Background(), name) }, } @@ -87,8 +87,10 @@ func Run(ctx context.Context, name string) error { }) input.SetDoneFunc(func(key tcell.Key) { - textView.Clear() - input.SetText("") + if key == tcell.KeyEscape { + textView.Clear() + input.SetText("") + } }) grid := tview.NewGrid(). diff --git a/db/db.go b/db/db.go index 746c30d..b28dea2 100644 --- a/db/db.go +++ b/db/db.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" "fmt" + "os" "github.com/mattn/go-sqlite3" ) @@ -42,9 +43,8 @@ func (d *DB) Migrate(ctx context.Context) error { _, err := d.db.ExecContext( ctx, `CREATE VIRTUAL TABLE IF NOT EXISTS words USING fts5 (word, line); - CREATE VIRTUAL TABLE IF NOT EXISTS words_terms USING fts4aux(words); - CREATE VIRTUAL TABLE IF NOT EXISTS spell USING spellfix1; - `, + CREATE VIRTUAL TABLE IF NOT EXISTS words_vocab USING fts5vocab('words', 'row'); + CREATE VIRTUAL TABLE IF NOT EXISTS spell USING spellfix1;`, ) return err } @@ -100,7 +100,7 @@ func (d *DB) SelectSpell(ctx context.Context, query string) ([]string, error) { words = append(words, w) } - return words, err + return words, nil } @@ -119,8 +119,7 @@ func (d *DB) InsertLine(ctx context.Context, word, line string) error { func (d *DB) Consolidade(ctx context.Context) error { _, err := d.db.ExecContext( ctx, - `INSERT INTO spell(word,rank) - SELECT term, documents FROM words_terms WHERE col='*'`, + `INSERT INTO spell(word) SELECT term FROM words_vocab`, ) if err != nil { return err @@ -139,6 +138,10 @@ func (d *DB) Backup(ctx context.Context, name string) error { } func (d *DB) Restore(ctx context.Context, name string) error { + if _, err := os.Stat(name); err != nil { + return err + } + srcDb, err := sql.Open("sqlite3_with_extensions", name) if err != nil { return err -- cgit v1.2.3