tag search
This commit is contained in:
@@ -311,6 +311,18 @@ async def tag_counts() -> list[dict]:
|
||||
async def search_notes(query: str, limit: int = 50) -> list[dict]:
|
||||
async with aiosqlite.connect(settings.database_path) as db:
|
||||
db.row_factory = aiosqlite.Row
|
||||
if query.lstrip().startswith("#"):
|
||||
tag = query.lstrip()[1:].strip()
|
||||
rows = await db.execute(
|
||||
"SELECT n.id, n.title, n.updated_at, n.created_at, u.name AS username"
|
||||
" FROM tags t"
|
||||
" JOIN note_tags nt ON nt.tag_id = t.id"
|
||||
" JOIN notes n ON n.id = nt.note_id AND n.deleted_at IS NULL"
|
||||
" JOIN users u ON u.id = n.user_id"
|
||||
" WHERE t.name = ? ORDER BY n.updated_at DESC LIMIT ?",
|
||||
(tag, limit),
|
||||
)
|
||||
else:
|
||||
rows = await db.execute(
|
||||
"SELECT f.note_id AS id, f.title, f.body, n.updated_at,"
|
||||
" n.created_at, u.name AS username, bm25(notes_fts) AS rank"
|
||||
|
||||
Reference in New Issue
Block a user