Site Search Integration
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The Site Search Integration within the Lou Gehrig Fan Club (LGFC) project provides a localized and modular approach to content discovery. Rather than a monolithic search engine, the system utilizes specialized search capabilities within specific modules, such as the Frequently Asked Questions (FAQ) system and the Photo/Memorabilia archives. This integration allows users to filter community-contributed content, approved documentation, and historical archives effectively.
The search functionality is primarily client-side for immediate UI feedback, supplemented by server-side query parameters for deeper filtering via Cloudflare Pages Functions and the D1 database. This ensures a fast, responsive user experience while maintaining the ability to query large datasets stored in the project's relational database.
Sources: context.md, src/app/faq/page.tsx:1-10, lgfc-lite-configure-remaining.sh:176-200
Architecture and Data Flow
The search architecture follows a pattern where the frontend captures user input and either filters a pre-loaded local state or initiates a new request to a backend API endpoint.
Search Flow Overview
The following diagram illustrates how search queries are handled between the client-side UI and the Cloudflare D1 database.
The system distinguishes between "Search by Keyword" (used in FAQs) and "Filter by Attribute" (used in Photo/Memorabilia archives).
Sources: src/app/faq/page.tsx:47-83, src/components/FAQSection.tsx:83-112
Module-Specific Search Implementations
FAQ Search Logic
The FAQ search implementation combines an initial data fetch with client-side memoized filtering. When a user types into the search box, the filteredItems useMemo hook executes a case-insensitive search across both the question and answer fields of the loaded FAQ items.
| Component | Logic Type | Search Fields |
|---|---|---|
FAQContent | Client-side Filter | question, answer |
FAQSection | API-driven Fetch | q query parameter |
In the FAQSection component, if a query is present, the API request limit is increased from 5 to 10 to provide more relevant results to the user.
Sources: src/app/faq/page.tsx:85-95, src/components/FAQSection.tsx:90-94
Media Archive Filtering
The Photo and Memorabilia archives utilize a server-side filtering approach via the /api/photos/list endpoint. This endpoint accepts parameters to distinguish between general photos and specific memorabilia items.
API Integration and Parameters
Search and filtering are facilitated by Cloudflare Pages Functions that interface with the D1 SQL database. These endpoints use standard URL search parameters to modify the executed SQL queries.
Search Query Parameters
The following table summarizes the parameters used across search-enabled API endpoints:
| Parameter | Type | Description | Module |
|---|---|---|---|
q | string | The search keyword or phrase | FAQ, Search |
limit | number | Maximum number of results to return (capped at 50 or 100) | FAQ, Photos, Library |
offset | number | Pagination offset for large result sets | Photos, Memorabilia |
memorabilia | boolean | Binary filter for item category (1 = true) | Photos |
status | string | Filter for moderation state (e.g., 'approved', 'pending') | Admin CMS/FAQ |
Sources: functions/api/photos/list.ts:6-15, src/app/admin/faq/page.tsx:68-75, lgfc-lite-configure-remaining.sh:213-225
Admin Content Management Search
The Administrative interface includes a search/filter capability for CMS blocks and FAQ entries based on "Slugs" and "Keys". The AdminCMS component allows administrators to select content blocks by their unique key or filter blocks belonging to specific site pages.
// Example of slug-based lookup in Admin Content
const load = useCallback(async (nextSlug?: string) => {
const target = (nextSlug ?? slug).trim() || '/';
const res = await fetch(`${apiBase}?slug=${encodeURIComponent(target)}`, {
method: 'GET',
headers: { 'content-type': 'application/json' },
});
// ... processing
}, [apiBase, slug]);
Sources: src/app/admin/content/page.tsx:55-75, src/app/admin/cms/page.tsx:49-62
Conclusion
The Site Search Integration in this template is designed for high performance on a static-export architecture. By leveraging Cloudflare D1 for server-side filtering and React's useMemo for client-side searching, the project maintains a "fail-closed" and responsive search experience. This modular approach ensures that as new content types (like Library entries or Photo archives) are added, they can implement optimized search patterns tailored to their specific data structures.