diff --git a/app/api/documents.py b/app/api/documents.py index ce168f7..78f206e 100644 --- a/app/api/documents.py +++ b/app/api/documents.py @@ -710,8 +710,19 @@ async def clause_lookup( await session.execute( sql_text( """ - SELECT c.doc_id, d.title AS doc_title, c.section_title, - c.char_start, c.id AS chunk_id, c.node_type + SELECT c.doc_id, d.title AS doc_title, c.section_title, c.char_start, c.node_type, + -- 점프 타깃 = outline(/sections: is_leaf 또는 %_split)에 있는 chunk 여야 딥링크 동작. + -- 자신이 그러면 자신, 아니면(컨테이너 절: 자식 heading 보유·is_leaf=false) 문서순서상 + -- 자신 이후 첫 딥링크 가능 chunk(=그 절 내용 시작)로 해소. 그래도 없으면 자신(폴백). + COALESCE( + CASE WHEN c.is_leaf = true OR c.node_type LIKE '%\\_split' ESCAPE '\\' THEN c.id END, + (SELECT ch.id FROM document_chunks ch + WHERE ch.doc_id = c.doc_id AND ch.source_type = 'hier_section' + AND ch.chunk_index >= c.chunk_index + AND (ch.is_leaf = true OR ch.node_type LIKE '%\\_split' ESCAPE '\\') + ORDER BY ch.chunk_index LIMIT 1), + c.id + ) AS chunk_id FROM document_chunks c JOIN documents d ON d.id = c.doc_id WHERE c.node_type IN ('clause', 'clause_split') diff --git a/frontend/src/routes/clause/+page.svelte b/frontend/src/routes/clause/+page.svelte index 49a5138..770f9a8 100644 --- a/frontend/src/routes/clause/+page.svelte +++ b/frontend/src/routes/clause/+page.svelte @@ -61,7 +61,7 @@ {/if} {#each hits as hit (hit.chunk_id)}