Skip to content

Commit

Permalink
add entries.title to search, missing highlight #33
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed Apr 7, 2024
1 parent 0783e8a commit 485f9f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion backend/src/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func initTables(db *sql.DB) error {
create virtual table search using fts5(
entriesid unindexed,
title,
content
);
`
Expand Down Expand Up @@ -148,7 +149,9 @@ func (feeds Feeds) Save(db *sql.DB) error {
return err
}
defer stmt_entry_content.Close()
stmt_entry_search, err := tx.Prepare("INSERT INTO search(entriesid,content) VALUES (?,?)")
stmt_entry_search, err := tx.Prepare(
"INSERT INTO search(entriesid,title,content) VALUES (?,?,?)",
)
if err != nil {
return err
}
Expand Down Expand Up @@ -211,6 +214,7 @@ func (feeds Feeds) Save(db *sql.DB) error {
}
_, err = stmt_entry_search.Exec(
lastEntryId,
entry.Title,
entry.Content,
)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions frontend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export async function search(dbarg, needle) {
entries.datemillis
FROM search
JOIN entries ON search.entriesid=entries.id
WHERE search.content MATCH $match
WHERE search MATCH $match
ORDER BY entries.feedid,entries.id DESC`,
bind: {$match: needle},
callback: (msg) => {
Expand All @@ -102,11 +102,11 @@ export async function getEntryDetails(dbarg, entryId, needle) {
let result;
if (needle && typeof needle === "string" && needle.length > 0) {
await db('exec', {
sql: `SELECT entries.feedid, highlight(search,1,'\`\`\`','\`\`\`')
sql: `SELECT entries.feedid, highlight(search,2,'\`\`\`','\`\`\`')
FROM entries
JOIN search ON entries.id=search.entriesid
WHERE entries.id=$eid
AND search.content MATCH $needle`,
AND search MATCH $needle`,
bind: {$eid: entryId, $needle: needle},
callback: (msg) => {
if (msg.row) {
Expand Down

0 comments on commit 485f9f2

Please sign in to comment.