Search Page Implementation
The search page is located atsrc/pages/[lang]/buscar.astro and uses Astro’s static site generation with client-side JavaScript for interactivity.
Data Preparation
All words are loaded at build time and serialized to JSON for client-side filtering:Search Algorithm
Text Normalization
The search normalizes text to handle accents and case-insensitivity:- Convert to lowercase:
"Guacamaya"→"guacamaya" - Decompose accented characters:
"búho"→"búho"(separates accent marks) - Remove diacritical marks:
"búho"→"buho"
Search Function
The core search logic filters across multiple fields:word- The Guatemalan slang termmeaning- The definition/meaningcategory- Word type (sustantivo, verbo, etc.)
URL Parameter Support
The search supports pre-filling via URL query parameters:/es/buscar/?q=chucho- Searches for “chucho”/en/buscar/?q=verbo- Searches for “verbo”
Results Rendering
No Results State
When no matches are found:Results Grid
Results are displayed in a responsive grid:Category Colors
Categories are color-coded for visual distinction:Event Handling
Input Event Listener
Search triggers on every keystroke:Form Submission Prevention
Prevent page reload on form submit:Analytics Integration
Search results are tracked with Umami analytics:- Which words users click from search results
- Category distribution of clicked words
- Search effectiveness
Internationalization
Search translations are passed to the client:Performance Considerations
Client-side filtering
Client-side filtering
All filtering happens in the browser, which:
- Provides instant results with no network latency
- Works offline after initial page load
- Scales well for dictionaries with hundreds of words
- May need optimization for thousands of entries
Data serialization
Data serialization
Only essential fields are serialized:Examples, synonyms, and other heavy data are excluded to reduce bundle size.
Search debouncing
Search debouncing
Currently, search triggers on every keystroke. For larger datasets, consider debouncing: