Fix drafts search to include author names
Clicking an author in the network graph opens /drafts?q=AuthorName but search only checked draft name/title/summary. Now also matches against author names via a JOIN on draft_authors + authors tables. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -74,6 +74,17 @@ def get_drafts_page(
|
|||||||
"""
|
"""
|
||||||
pairs = db.drafts_with_ratings(limit=1000)
|
pairs = db.drafts_with_ratings(limit=1000)
|
||||||
|
|
||||||
|
# Build author lookup for search (draft_name -> "author1 author2 ...")
|
||||||
|
author_text_by_draft: dict[str, str] = {}
|
||||||
|
if search:
|
||||||
|
rows = db.conn.execute(
|
||||||
|
"""SELECT da.draft_name, GROUP_CONCAT(a.name, ' ') as names
|
||||||
|
FROM draft_authors da JOIN authors a ON da.person_id = a.person_id
|
||||||
|
GROUP BY da.draft_name"""
|
||||||
|
).fetchall()
|
||||||
|
for r in rows:
|
||||||
|
author_text_by_draft[r[0]] = r[1] or ""
|
||||||
|
|
||||||
# Filter
|
# Filter
|
||||||
filtered = []
|
filtered = []
|
||||||
for draft, rating in pairs:
|
for draft, rating in pairs:
|
||||||
@@ -84,7 +95,8 @@ def get_drafts_page(
|
|||||||
if source and draft.source != source:
|
if source and draft.source != source:
|
||||||
continue
|
continue
|
||||||
if search:
|
if search:
|
||||||
haystack = f"{draft.name} {draft.title} {rating.summary}".lower()
|
author_names = author_text_by_draft.get(draft.name, "")
|
||||||
|
haystack = f"{draft.name} {draft.title} {rating.summary} {author_names}".lower()
|
||||||
if not all(w in haystack for w in search.lower().split()):
|
if not all(w in haystack for w in search.lower().split()):
|
||||||
continue
|
continue
|
||||||
filtered.append((draft, rating))
|
filtered.append((draft, rating))
|
||||||
|
|||||||
Reference in New Issue
Block a user