feat: 전체 판례 검색과 판례 탭 추가
This commit is contained in:
1 parent
fa15117df7
commit
5386222f1b
11 files changed
+443
-44
No files matched your search
+66
-1
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from fastapi import APIRouter, BackgroundTasks, File, Form, HTTPException, Request, UploadFile, status
|
||||
from fastapi import APIRouter, BackgroundTasks, File, Form, HTTPException, Query, Request, UploadFile, status
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
from app.api.schemas import (
|
||||
@@ -21,6 +21,8 @@ from app.api.schemas import (
|
||||
DetectRequest,
|
||||
DetectResponse,
|
||||
HealthResponse,
|
||||
PrecedentItem,
|
||||
PrecedentListResponse,
|
||||
SummaryRequest,
|
||||
SummaryResponse,
|
||||
TaxonomyResponse,
|
||||
@@ -240,6 +242,69 @@ async def batch_status(job_id: str, request: Request) -> BatchStatusResponse:
|
||||
)
|
||||
|
||||
|
||||
# ---------- 판례 조회 ----------
|
||||
|
||||
@router.get(
|
||||
"/precedents",
|
||||
response_model=PrecedentListResponse,
|
||||
tags=["precedents"],
|
||||
)
|
||||
async def precedent_list(
|
||||
request: Request,
|
||||
q: str = Query(default="", max_length=200),
|
||||
grade: str | None = Query(default=None, pattern="^(A|B|C|unreviewed)$"),
|
||||
work_type: str | None = Query(default=None, max_length=30),
|
||||
offset: int = Query(default=0, ge=0),
|
||||
limit: int = Query(default=25, ge=1, le=100),
|
||||
) -> PrecedentListResponse:
|
||||
"""엔진이 검색 후보로 사용하는 전체 판례를 조회한다."""
|
||||
precedents = list(_detector(request).precedents)
|
||||
needle = q.strip().lower()
|
||||
|
||||
def matches(p) -> bool:
|
||||
if grade == "unreviewed" and p.grade is not None:
|
||||
return False
|
||||
if grade in {"A", "B", "C"} and p.grade != grade:
|
||||
return False
|
||||
if work_type and p.work_types and work_type not in p.work_types:
|
||||
return False
|
||||
if needle:
|
||||
haystack = " ".join([
|
||||
p.case_id, p.title, *p.work_types, *p.legal_tags,
|
||||
*p.criteria, p.holding_summary,
|
||||
]).lower()
|
||||
if needle not in haystack:
|
||||
return False
|
||||
return True
|
||||
|
||||
filtered = [p for p in precedents if matches(p)]
|
||||
page = filtered[offset:offset + limit]
|
||||
return PrecedentListResponse(
|
||||
total=len(filtered),
|
||||
loaded_total=len(precedents),
|
||||
graded_total=sum(p.grade is not None for p in precedents),
|
||||
offset=offset,
|
||||
limit=limit,
|
||||
items=[
|
||||
PrecedentItem(
|
||||
case_id=p.case_id,
|
||||
title=p.title,
|
||||
source_url=p.source_url,
|
||||
work_types=list(p.work_types),
|
||||
legal_tags=list(p.legal_tags),
|
||||
criteria=list(p.criteria),
|
||||
grade=p.grade,
|
||||
holding_excerpt=(
|
||||
p.holding_summary
|
||||
if len(p.holding_summary) <= 800
|
||||
else p.holding_summary[:800].rstrip() + "…"
|
||||
),
|
||||
)
|
||||
for p in page
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
# ---------- 코퍼스 관리 ----------
|
||||
|
||||
def _rebuild(request: Request) -> int:
|
||||
|
||||
Reference in new issue
Block a user