실거래가 조회 및 출력

This commit is contained in:
jaehwang committed 2025-08-19 14:57:03 +09:00
1 parent 5bf283c5d4
commit 3d1f8683a4
10 files changed
+701 -192

No files matched your search

+4 -4
View File
@@ -9,8 +9,8 @@
<body>
<div class="container">
<header>
<h1>🏠 부동산 자연어 검색</h1>
<p>원하시는 부동산 조건을 자유롭게 입력해주세요</p>
<h1>🏠 부동산 실거래가 검색</h1>
<p>원하시는 부동산 조건을 자유롭게 입력하면 실거래가를 조회합니다</p>
</header>
<main>
@@ -34,13 +34,13 @@
</div>
<div id="resultSection" class="result-section" style="display: none;">
<h2>📊 분석 결과</h2>
<h2>📊 검색 결과</h2>
<div id="resultContent"></div>
</div>
<div id="loadingSection" class="loading" style="display: none;">
<div class="spinner"></div>
<p>AI가 분석 중입니다...</p>
<p>실거래가 데이터를 조회 중입니다...</p>
</div>
</main>
</div>
+144 -43
View File
@@ -18,7 +18,8 @@ async function parseQuery() {
document.getElementById('searchBtn').disabled = true;
try {
const response = await fetch('/api/parse', {
// /api/search 엔드포인트 호출 (파싱 + 실거래가 조회)
const response = await fetch('/api/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -48,58 +49,158 @@ function displayResults(data) {
let html = '';
if (data.property_type) {
html += `<div class="result-item">
<strong>매물 형태:</strong> ${data.property_type}
</div>`;
}
if (data.transaction_type) {
html += `<div class="result-item">
<strong>거래 유형:</strong> ${data.transaction_type}
</div>`;
}
if (data.price) {
html += `<div class="result-item">
<strong>가격:</strong> ${data.price}
</div>`;
}
if (data.location) {
html += `<div class="result-item">
<strong>위치:</strong> ${data.location}
</div>`;
// 파싱된 정보 요약
if (data.parsed) {
html += '<div class="search-summary">';
html += '<h3>🔍 검색 조건</h3>';
html += '<div class="summary-items">';
// 지역 코드가 있으면 표시
if (data.region_code) {
html += `<div class="result-item">
<strong>지역 코드:</strong> ${data.region_code}
${data.region_name ? ` (${data.region_name})` : ''}
</div>`;
if (data.parsed.property_type) {
html += `<span class="summary-item">${data.parsed.property_type}</span>`;
}
if (data.parsed.transaction_type) {
html += `<span class="summary-item">${data.parsed.transaction_type}</span>`;
}
if (data.parsed.location) {
html += `<span class="summary-item">${data.parsed.location}</span>`;
}
if (data.parsed.region_name) {
html += `<span class="summary-item">${data.parsed.region_name}</span>`;
}
html += '</div>';
html += '</div>';
}
if (data.area) {
html += `<div class="result-item">
<strong>면적:</strong> ${data.area}
</div>`;
}
if (data.rooms) {
html += `<div class="result-item">
<strong>방 개수:</strong> ${data.rooms}개
</div>`;
}
if (!html) {
html = '<p>추출된 정보가 없습니다. 더 구체적으로 입력해주세요.</p>';
// 실거래가 목록
if (data.listings && data.listings.length > 0) {
html += '<div class="listings-section">';
html += `<h3>📊 실거래가 정보 (${data.count}건)</h3>`;
html += '<div class="listings-container">';
// 최대 20개만 표시
const displayCount = Math.min(data.listings.length, 20);
for (let i = 0; i < displayCount; i++) {
const item = data.listings[i];
html += createListingCard(item);
}
if (data.listings.length > 20) {
html += `<p class="more-info">... 외 ${data.listings.length - 20}건</p>`;
}
html += '</div>';
html += '</div>';
} else {
html += '<div class="no-results">';
html += '<p>😔 검색 결과가 없습니다.</p>';
if (!data.parsed.region_code) {
html += '<p>지역 정보를 더 구체적으로 입력해주세요.</p>';
} else {
html += '<p>다른 조건으로 검색해보세요.</p>';
}
html += '</div>';
}
resultContent.innerHTML = html;
document.getElementById('resultSection').style.display = 'block';
}
// 실거래가 카드 생성
function createListingCard(item) {
let html = '<div class="listing-card">';
// 제목 (아파트명 또는 주소)
const title = item['아파트'] || item['법정동'] || '정보 없음';
html += `<h4>${title}</h4>`;
// 거래 정보
html += '<div class="listing-info">';
// 거래금액
if (item['거래금액']) {
const price = item['거래금액'].replace(/,/g, '').trim();
const priceNum = parseInt(price);
const priceText = priceNum >= 10000 ?
`${(priceNum / 10000).toFixed(1)}억` :
`${priceNum.toLocaleString()}만원`;
html += `<div class="info-item">
<span class="label">거래금액</span>
<span class="value price">${priceText}</span>
</div>`;
}
// 보증금 (전세/월세)
if (item['보증금액']) {
const deposit = item['보증금액'].replace(/,/g, '').trim();
const depositNum = parseInt(deposit);
const depositText = depositNum >= 10000 ?
`${(depositNum / 10000).toFixed(1)}억` :
`${depositNum.toLocaleString()}만원`;
html += `<div class="info-item">
<span class="label">보증금</span>
<span class="value">${depositText}</span>
</div>`;
}
// 월세
if (item['월세금액'] && item['월세금액'] !== '0') {
html += `<div class="info-item">
<span class="label">월세</span>
<span class="value">${item['월세금액']}만원</span>
</div>`;
}
// 면적
if (item['전용면적']) {
const area = parseFloat(item['전용면적']);
const pyeong = (area / 3.3).toFixed(1);
html += `<div class="info-item">
<span class="label">면적</span>
<span class="value">${area}㎡ (${pyeong}평)</span>
</div>`;
}
// 층
if (item['층']) {
html += `<div class="info-item">
<span class="label">층</span>
<span class="value">${item['층']}층</span>
</div>`;
}
// 거래일
if (item['년'] && item['월'] && item['일']) {
html += `<div class="info-item">
<span class="label">거래일</span>
<span class="value">${item['년']}.${item['월']}.${item['일']}</span>
</div>`;
}
// 건축년도
if (item['건축년도']) {
const age = new Date().getFullYear() - parseInt(item['건축년도']);
html += `<div class="info-item">
<span class="label">건축년도</span>
<span class="value">${item['건축년도']}년 (${age}년)</span>
</div>`;
}
// 주소
if (item['법정동'] && item['지번']) {
html += `<div class="info-item full-width">
<span class="label">주소</span>
<span class="value">${item['법정동']} ${item['지번']}</span>
</div>`;
}
html += '</div>';
html += '</div>';
return html;
}
// Enter 키로 검색
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('searchInput').addEventListener('keypress', function(e) {
+114
View File
@@ -158,4 +158,118 @@ header p {
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* 검색 요약 */
.search-summary {
background: #f8f9fa;
padding: 15px;
border-radius: 10px;
margin-bottom: 20px;
}
.search-summary h3 {
color: #333;
font-size: 1.1em;
margin-bottom: 10px;
}
.summary-items {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.summary-item {
background: #667eea;
color: white;
padding: 5px 12px;
border-radius: 15px;
font-size: 0.9em;
}
/* 실거래가 목록 */
.listings-section {
margin-top: 20px;
}
.listings-section h3 {
color: #333;
margin-bottom: 15px;
}
.listings-container {
display: grid;
gap: 15px;
}
.listing-card {
background: white;
border: 1px solid #e0e0e0;
border-radius: 10px;
padding: 15px;
transition: all 0.3s;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.listing-card:hover {
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
transform: translateY(-2px);
}
.listing-card h4 {
color: #667eea;
margin-bottom: 12px;
font-size: 1.1em;
}
.listing-info {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 10px;
}
.info-item {
display: flex;
flex-direction: column;
gap: 3px;
}
.info-item.full-width {
grid-column: 1 / -1;
}
.info-item .label {
color: #888;
font-size: 0.85em;
}
.info-item .value {
color: #333;
font-weight: 500;
}
.info-item .value.price {
color: #667eea;
font-size: 1.1em;
font-weight: bold;
}
.no-results {
text-align: center;
padding: 40px;
background: #f8f9fa;
border-radius: 10px;
}
.no-results p {
margin: 10px 0;
color: #666;
}
.more-info {
text-align: center;
color: #888;
margin-top: 20px;
font-style: italic;
}