tag search

This commit is contained in:
schmeeve
2026-09-23 21:47:46 -07:00
parent ff620a23ed
commit 92883d63f5

View File

@@ -311,6 +311,18 @@ async def tag_counts() -> list[dict]:
async def search_notes(query: str, limit: int = 50) -> list[dict]: async def search_notes(query: str, limit: int = 50) -> list[dict]:
async with aiosqlite.connect(settings.database_path) as db: async with aiosqlite.connect(settings.database_path) as db:
db.row_factory = aiosqlite.Row 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( rows = await db.execute(
"SELECT f.note_id AS id, f.title, f.body, n.updated_at," "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" " n.created_at, u.name AS username, bm25(notes_fts) AS rank"