Save HTML content to database

This commit is contained in:
Radhi Fadlillah 2018-01-30 16:20:18 +07:00
parent a454641d81
commit cd5a74a123
3 changed files with 7 additions and 5 deletions

View file

@ -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))

View file

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

View file

@ -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"`
}