import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common'; import { MatchService } from './match.service'; import { ServingService } from './serving.service'; @Controller('v1') export class ServingController { constructor( private readonly serving: ServingService, private readonly matcher: MatchService, ) {} /** 발행된 사이트가 렌더링 시 호출 — SEO 메타 */ @Get('sites/:id/seo') seo(@Param('id') id: string, @Query('limit') limit?: string) { return this.serving.seo(id, clamp(limit, 20, 50)); } /** 발행된 사이트가 렌더링 시 호출 — AEO(답변엔진) 소스 */ @Get('sites/:id/aeo') aeo(@Param('id') id: string, @Query('limit') limit?: string) { return this.serving.aeo(id, clamp(limit, 10, 30)); } /** 어드민: 의미 기반 키워드 검색 */ @Post('keywords/search') search(@Body() body: { query: string; limit?: number }) { return this.serving.searchKeywords(body.query, Math.min(body.limit ?? 10, 50)); } /** * 자유 입력(업체명/문장) → 적재된 사전에서 잘 맞는 키워드. * mode=fusion (기본) — 속성별 서브 질의 + 가중 RRF + 사실 기반 필터 * mode=single — 프로필을 통짜로 한 벡터에 넣는 이전 방식 (비교용) */ @Post('match') match(@Body() body: { query: string; limit?: number; mode?: 'fusion' | 'single' }) { const limit = Math.min(body.limit ?? 40, 200); return body.mode === 'single' ? this.serving.match(body.query ?? '', limit) : this.matcher.fusion(body.query ?? '', limit); } /** 성과 피드백 주입 (Search Console / 유입 로그) */ @Post('sites/:id/performance') performance( @Param('id') id: string, @Body() body: { items: Array<{ keyword: string; impressions: number; clicks: number }> }, ) { return this.serving.applyPerformance(id, body.items ?? []); } } function clamp(v: string | undefined, def: number, max: number): number { const n = v ? Number(v) : def; return Number.isFinite(n) ? Math.min(Math.max(1, n), max) : def; }