diff --git a/adapter/sqlite/dao_note.go b/adapter/sqlite/dao_note.go index c3e2219..91828f5 100644 --- a/adapter/sqlite/dao_note.go +++ b/adapter/sqlite/dao_note.go @@ -161,12 +161,12 @@ func (d *NoteDAO) Find(callback func(note.Match) error, filters ...note.Filter) return d.tx.Query(` SELECT n.id, n.dir, n.filename, n.title, n.body, n.word_count, n.created, n.modified, n.checksum, - snippet(notes_fts, -1, '\033[31m', '\033[0m', '…', 20) as snippet + snippet(notes_fts, -1, '', '', '…', 20) as snippet FROM notes n JOIN notes_fts ON n.id = notes_fts.rowid WHERE notes_fts MATCH ? - ORDER BY bm25(notes_fts, 1000.0, 1.0) + ORDER BY bm25(notes_fts, 1000.0, 500.0, 1.0) --- ORDER BY rank `, filter) } diff --git a/adapter/sqlite/db.go b/adapter/sqlite/db.go index 21824d1..00bf20a 100644 --- a/adapter/sqlite/db.go +++ b/adapter/sqlite/db.go @@ -61,10 +61,11 @@ func (db *DB) Migrate() error { UNIQUE(filename, dir) ) `, - `CREATE INDEX IF NOT EXISTS notes_checksum_idx ON notes(checksum)`, + `CREATE INDEX IF NOT EXISTS index_notes_checksum ON notes (checksum)`, + `CREATE INDEX IF NOT EXISTS index_notes_dir_filename ON notes (dir, filename)`, ` CREATE VIRTUAL TABLE IF NOT EXISTS notes_fts USING fts5( - title, body, + filename, title, body, content = notes, content_rowid = id, tokenize = 'porter unicode61 remove_diacritics 1' @@ -73,18 +74,18 @@ func (db *DB) Migrate() error { // Triggers to keep the FTS index up to date. ` CREATE TRIGGER IF NOT EXISTS notes_ai AFTER INSERT ON notes BEGIN - INSERT INTO notes_fts(rowid, title, body) VALUES (new.id, new.title, new.body); + INSERT INTO notes_fts(rowid, filename, title, body) VALUES (new.id, new.filename, new.title, new.body); END `, ` CREATE TRIGGER IF NOT EXISTS notes_ad AFTER DELETE ON notes BEGIN - INSERT INTO notes_fts(notes_fts, rowid, title, body) VALUES('delete', old.id, old.title, old.body); + INSERT INTO notes_fts(notes_fts, rowid, filename, title, body) VALUES('delete', old.id, old.filename, old.title, old.body); END `, ` CREATE TRIGGER IF NOT EXISTS notes_au AFTER UPDATE ON notes BEGIN - INSERT INTO notes_fts(notes_fts, rowid, title, body) VALUES('delete', old.id, old.title, old.body); - INSERT INTO notes_fts(rowid, title, body) VALUES (new.id, new.title, new.body); + INSERT INTO notes_fts(notes_fts, rowid, filename, title, body) VALUES('delete', old.id, old.filename, old.title, old.body); + INSERT INTO notes_fts(rowid, filename, title, body) VALUES (new.id, new.filename, new.title, new.body); END `, `PRAGMA user_version = 1`,