Index the note filenames

This commit is contained in:
Mickaël Menu 2021-01-07 19:29:04 +01:00
parent 31c13c6af4
commit 5a8b6ec02f
No known key found for this signature in database
GPG Key ID: 53D73664CD359895
2 changed files with 9 additions and 8 deletions

View File

@ -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, '<zk:match>', '</zk:match>', '…', 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)
}

View File

@ -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`,