fix: 장소 검색이 이름 불일치로 끝나면 시·군·구를 붙여 재검색

This commit is contained in:
skkim committed 2026-11-12 11:33:02 +09:00
1 parent ea7539ee43
commit f2d11ad9d3
1 file changed
+36 -2
+36 -2
View File
@@ -544,17 +544,45 @@ if (originalQuery) {
return non_empty
return [] if captured else None
async def _try_search(self, address: str, title: str, jibun: str = "") -> str | None:
@staticmethod
def _region_hint(address: str) -> str:
"""주소에서 검색어 앞에 붙일 시·군·구 이름을 추출한다 (예: '군산시', '영등포구'). 없으면 빈 문자열.
'서울특별시' 같은 광역 단위는 제외한다.
"""
for token in (address or "").split():
if re.fullmatch(r"[가-힣]+(?:시|군|구)", token) and not token.endswith(
("특별시", "광역시", "특별자치시")
):
return token
return ""
async def _retry_with_region(self, address: str, title: str, jibun: str) -> str | None:
"""업체명만 검색해 이름 불일치로 끝났을 때, 시·군·구를 붙여 한 번 더 검색한다.
업체명이 일반적이면 네이버가 다른 지역의 동종 업체만 돌려주는 경우가 있다
(예: '선유도 리조트' → 서울 여의도의 다른 업체). 후보 검증은 그대로 적용된다.
"""
region = self._region_hint(address)
if not region or region in title:
return None
logger.info(f"[RETRY-REGION] 지역을 붙여 재검색: '{region} {title}'")
return await self._try_search(address, title, jibun, query=f"{region} {title}")
async def _try_search(
self, address: str, title: str, jibun: str = "", query: str | None = None
) -> str | None:
"""업체명으로 검색해 후보를 받고, 검증을 통과한 후보의 place URL을 반환한다. 실패 시 None.
검색어에는 주소를 넣지 않는다 (주소가 섞이면 네이버가 주소 검색으로 처리해 장소 목록이 비어 있음).
query 가 주어지면 검색어로만 쓰이고, 이름 유사도 검증은 항상 title 기준이다.
address/jibun 은 후보 검증(_pick_verified_candidate)에만 사용한다.
검색 응답을 받아 판단까지 마쳤다면(결과 0건 / 검증 실패 포함) _last_search_conclusive 를 True 로
남긴다. 재시도해도 결과가 달라지지 않으므로 호출자가 재시도를 생략하는 데 사용한다.
"""
self._last_search_conclusive = False
encoded_query = parse.quote(title)
encoded_query = parse.quote(query or title)
url = f"https://map.naver.com/p/search/{encoded_query}"
# 1순위: list 응답 캡처 (__APOLLO_STATE__ 파싱)
@@ -610,6 +638,9 @@ if (originalQuery) {
if result:
return result
if self._last_search_conclusive:
result = await self._retry_with_region(address, title, jibun)
if result:
return result
logger.warning(f"[NOT-FOUND] 검색 응답은 받았으나 일치하는 업체 없음 → 재시도 생략: '{title}'")
return None
@@ -620,6 +651,9 @@ if (originalQuery) {
if result:
return result
if self._last_search_conclusive:
result = await self._retry_with_region(address, title, jibun)
if result:
return result
logger.warning(f"[NOT-FOUND] 검색 응답은 받았으나 일치하는 업체 없음 → 재시도 생략: '{title}'")
return None