From cd5a74a123ab24020194efbcbb330a4451e88bee Mon Sep 17 00:00:00 2001 From: Radhi Fadlillah Date: Tue, 30 Jan 2018 16:20:18 +0700 Subject: [PATCH] Save HTML content to database --- cmd/add.go | 1 + database/sqlite.go | 10 +++++----- model/model.go | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/add.go b/cmd/add.go index aedd5ed0..e34a1094 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -62,6 +62,7 @@ func addBookmark(url, title, excerpt string, tags []string, offline bool) (err e MinReadTime: article.Meta.MinReadTime, MaxReadTime: article.Meta.MaxReadTime, Content: article.Content, + HTML: article.RawContent, } bookTags := make([]model.Tag, len(tags)) diff --git a/database/sqlite.go b/database/sqlite.go index 26bb8fa8..a2929ea7 100644 --- a/database/sqlite.go +++ b/database/sqlite.go @@ -66,7 +66,7 @@ func OpenSQLiteDatabase() (*SQLiteDatabase, error) { CONSTRAINT bookmark_id_FK FOREIGN KEY(bookmark_id) REFERENCES bookmark(id), CONSTRAINT tag_id_FK FOREIGN KEY(tag_id) REFERENCES tag(id))`) - tx.MustExec(`CREATE VIRTUAL TABLE IF NOT EXISTS bookmark_content USING fts4(title, content)`) + tx.MustExec(`CREATE VIRTUAL TABLE IF NOT EXISTS bookmark_content USING fts4(title, content, html)`) err = tx.Commit() checkError(err) @@ -121,8 +121,8 @@ func (db *SQLiteDatabase) SaveBookmark(bookmark model.Bookmark) (bookmarkID int6 // Save bookmark content tx.MustExec(`INSERT INTO bookmark_content - (docid, title, content) VALUES (?, ?, ?)`, - bookmarkID, bookmark.Title, bookmark.Content) + (docid, title, content, html) VALUES (?, ?, ?, ?)`, + bookmarkID, bookmark.Title, bookmark.Content, bookmark.HTML) // Save tags stmtGetTag, err := tx.Preparex(`SELECT id FROM tag WHERE name = ?`) @@ -375,8 +375,8 @@ func (db *SQLiteDatabase) SearchBookmarks(keyword string, tags ...string) ([]mod if keyword != "" { whereClause += ` AND id IN ( SELECT docid id FROM bookmark_content - WHERE bookmark_content MATCH ?)` - args = append(args, keyword) + WHERE title MATCH ? OR content MATCH ?)` + args = append(args, keyword, keyword) } // Create where clause for tags diff --git a/model/model.go b/model/model.go index 6ad79a5b..d743176b 100644 --- a/model/model.go +++ b/model/model.go @@ -17,5 +17,6 @@ type Bookmark struct { MaxReadTime int `db:"max_read_time" json:"maxReadTime"` Modified string `db:"modified" json:"modified"` Content string `db:"content" json:"-"` + HTML string `db:"html" json:"-"` Tags []Tag `json:"tags"` }