[feat] ontology: 새 숙소 키워드를 OpenAI 로 쌓고 매칭에 쓴다 — 호텔 업종 · 숙소 검색 정정
사전이 고정 데이터셋뿐이라 사전에 없는 숙소는 새 단어를 받지 못했고, 생성분은 MATCH_SOURCES 가 llm 을 빼서 만들어도 추천에 안 나왔다. 숙소 검색은 가까운 키워드를 사전 전체(7천)에서 뽑아 상위가 아무 숙소에도 안 붙은 단어로 차서 `선유도 독채` 가 0건이었다. - merchants.controller: 처음 보는 업체·기한 지난 업체만 생성, sync 는 처음 보는 업체만 기다림 — 재빌드마다 불리는 창구라 조건이 없으면 저장마다 요금. 동기 생성 실패는 200 + generation.failed - generation·dedup·keyword.repository: mock 생성분은 source='mock' — compose 기본이 mock 이라 키 없는 환경의 가짜 단어가 매칭 후보가 되지 않게 - match.service: llm 출처를 후보에 넣음(brand 는 그 업체 것만), 업종은 뿌리(stay)로 좁힘 — 새 호텔은 호텔 사전이 비어 잎으로 좁히면 후보 0건 - openai.provider: 미확인 시설·다른 숙박 유형어·가격 주장 금지 - drizzle/0002 · seed: stay.hotel — 시드만 두면 떠 있는 DB 에서 외래키 위반 500 - serving.service: 숙소에 연결된 키워드만 비교, 검색어가 지역을 말하면 그 지역 숙소만 — e5-small 은 지역이 틀려도 0.85(`여수 호텔` → 군산 호텔 0.848)라 임계값으로는 못 가른다 tsc 통과. 로컬 :3101 + 실 OpenAI(가짜 숙소 2곳): 첫 발행 7초 · 키워드 12 생성 · 재발행 fresh, 검색 7건(`은파호수공원 근처 호텔`·`선유도 독채`·`군산시내호텔` 적중, `여수 호텔` 0건) 확인 후 테스트 데이터 삭제 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
089886fe1e
commit
847943a8bc
12 files changed
+90
-44
No files matched your search
@@ -1,10 +1,13 @@
|
||||
import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Logger, Param, Post, Query } from '@nestjs/common';
|
||||
import { env } from '../config/env';
|
||||
import { GenerationService } from '../generation/generation.service';
|
||||
import { GenerationQueue } from '../generation/generation.queue';
|
||||
import { MerchantsService, UpsertMerchantDto } from './merchants.service';
|
||||
|
||||
@Controller('v1/merchants')
|
||||
export class MerchantsController {
|
||||
private readonly logger = new Logger(MerchantsController.name);
|
||||
|
||||
constructor(
|
||||
private readonly merchants: MerchantsService,
|
||||
private readonly generation: GenerationService,
|
||||
@@ -21,15 +24,25 @@ export class MerchantsController {
|
||||
return this.merchants.findWithTaxonomy(id);
|
||||
}
|
||||
|
||||
/** o2o-site-AEO 사이트 발행 웹훅: 업체 등록 + 키워드 생성 예약 */
|
||||
/** 발행 웹훅 — 재빌드마다 불리므로 처음 보는 업체·기한 지난 업체만 생성해 LLM 요금을 묶는다 */
|
||||
@Post('publish')
|
||||
async publish(@Body() dto: UpsertMerchantDto & { generate?: boolean; sync?: boolean }) {
|
||||
const merchant = await this.merchants.upsert(dto);
|
||||
if (dto.generate === false) return { merchant, generation: 'skipped' };
|
||||
if (!this.merchants.isStale(merchant, env.generation.refreshIntervalDays)) {
|
||||
return { merchant, generation: 'fresh' };
|
||||
}
|
||||
|
||||
if (dto.sync) {
|
||||
const stats = await this.generation.runForMerchant(merchant.id, 'published');
|
||||
return { merchant, generation: stats };
|
||||
// 첫 발행부터 새 키워드가 실리도록 처음 보는 업체만 기다린다. 실패해도 사전 키워드로 발행은 나간다.
|
||||
if (dto.sync && merchant.last_generated_at === null) {
|
||||
try {
|
||||
const stats = await this.generation.runForMerchant(merchant.id, 'published');
|
||||
return { merchant, generation: { ...stats, details: undefined } };
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
this.logger.warn(`[${merchant.name}] 동기 생성 실패 — 사전 키워드로만 매칭된다: ${message}`);
|
||||
return { merchant, generation: { failed: true, error: message } };
|
||||
}
|
||||
}
|
||||
const jobId = await this.queue.enqueue(merchant.id, 'published');
|
||||
return { merchant, generation: { queued: true, jobId } };
|
||||
|
||||
@@ -83,6 +83,12 @@ export class MerchantsService {
|
||||
LIMIT ${limit}`;
|
||||
}
|
||||
|
||||
/** findStale 과 같은 기준을 행 하나에 — publish 가 생성 여부를 정할 때 쓴다 */
|
||||
isStale(merchant: Pick<MerchantRow, 'last_generated_at'>, intervalDays: number): boolean {
|
||||
if (!merchant.last_generated_at) return true;
|
||||
return Date.now() - new Date(merchant.last_generated_at).getTime() > intervalDays * 86_400_000;
|
||||
}
|
||||
|
||||
async markGenerated(merchantId: string) {
|
||||
await this.sql`UPDATE merchant SET last_generated_at = now() WHERE id = ${merchantId}`;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user