fix err in keyword searching (#494)

This commit is contained in:
hulb 2022-10-09 23:05:01 +08:00 committed by GitHub
parent d15dc18674
commit 821b69d76c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View file

@ -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 + "%"
@ -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 + "%"

View file

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