/** * SignHall AI Search & Q&A Page Logic * Natural language query processing with structured data retrieval */ import { injectLayout, renderExhibitCard } from './layout.js'; import { getAllExhibits } from './data.js'; import { generateAIAnswer, getSuggestedQueries } from './search.js'; import { CATEGORIES } from './config.js'; let allExhibits = []; async function initAISearch() { injectLayout('search'); allExhibits = await getAllExhibits(); // Render suggestion chips const chips = getSuggestedQueries(); const chipsContainer = document.getElementById('suggestion-chips'); chipsContainer.innerHTML = chips.map(q => `${escapeHtml(q)}` ).join(''); // Click on suggestion chips chipsContainer.querySelectorAll('.ai-chip').forEach(chip => { chip.addEventListener('click', () => { const query = chip.getAttribute('data-query'); document.getElementById('ai-input').value = query; handleSearch(query); }); }); // Form submit document.getElementById('ai-form').addEventListener('submit', (e) => { e.preventDefault(); const query = document.getElementById('ai-input').value.trim(); if (query) handleSearch(query); }); // Auto-search if query is in URL const params = new URLSearchParams(window.location.search); const q = params.get('q'); if (q) { document.getElementById('ai-input').value = q; handleSearch(q); } } async function handleSearch(query) { const answerArea = document.getElementById('ai-answer-area'); // Show loading answerArea.innerHTML = `
Searching structured exhibit data...
An error occurred while processing your query. Please try again.
')
.replace(/\n/g, '
');
// Exhibit cards
const exhibitCards = result.exhibits.slice(0, 6).map(ex => renderExhibitCard(ex)).join('');
answerArea.innerHTML = `
${formattedAnswer}