Skip to content

Commit

Permalink
fix err in keyword searching (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
hulb committed Oct 9, 2022
1 parent d15dc18 commit 821b69d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/database/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ func (db *PGDatabase) GetBookmarks(ctx context.Context, opts GetBookmarksOptions
if opts.Keyword != "" {
query += ` AND (
url LIKE :lkw OR
MATCH(title, excerpt, content) AGAINST (:kw IN BOOLEAN MODE)
title LIKE :kw OR
excerpt LIKE :kw OR
content LIKE :kw
)`

arg["lkw"] = "%" + opts.Keyword + "%"
Expand Down Expand Up @@ -356,7 +358,9 @@ func (db *PGDatabase) GetBookmarksCount(ctx context.Context, opts GetBookmarksOp
if opts.Keyword != "" {
query += ` AND (
url LIKE :lurl OR
MATCH(title, excerpt, content) AGAINST (:kw IN BOOLEAN MODE)
title LIKE :kw OR
excerpt LIKE :kw OR
content LIKE :kw
)`

arg["lurl"] = "%" + opts.Keyword + "%"
Expand Down
4 changes: 4 additions & 0 deletions internal/database/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ func (db *SQLiteDatabase) GetBookmarks(ctx context.Context, opts GetBookmarksOpt
bookmarkIds = append(bookmarkIds, book.ID)
}

if len(bookmarkIds) == 0 {
return bookmarks, nil
}

// If content needed, fetch it separately
// It's faster than join with virtual table
if opts.WithContent {
Expand Down

0 comments on commit 821b69d

Please sign in to comment.