Looking at your Svelte app code, I can see the search logic is currently handled on the frontend in JavaScript/TypeScript within the reactive statement in App.svelte
. Here's the current search implementation:
$: {
const sourceData = glyphData.filter((item, index, self) => index === self.findIndex((g) => g.name === item.name));
if (searchTerm.trim() === "") {
filteredGlyphs = sourceData;
} else {
const lowercasedFilter = searchTerm.toLowerCase();
filteredGlyphs = sourceData.filter((item) => item.name.toLowerCase().includes(lowercasedFilter));
}
}
Yes, this can definitely be moved to Go and optimized significantly! Here's how you can implement a much faster search backend:Now you'll need to update your Svelte frontend to use the Go backend for search. Here's the updated frontend code:## Key Optimizations in the Go Implementation:
Preprocessing & Indexing: The search data is preprocessed once at startup, creating multiple efficient data structures:
Multiple Search Strategies:
Relevance Scoring: Results are ranked by relevance, considering:
String Normalization: Handles case-insensitive search, removes diacritics, and normalizes separators.
Concurrent Safety: Uses read-write mutexes for thread-safe operations.
Memory Efficiency: Deduplication happens once at initialization rather than on every search.
glyphsJSON
in initializeSearchIndex()
with actual JSON loadingwails.json
to generate the new Go method bindingsThis approach leverages Go's superior string processing and memory management while maintaining a responsive user interface. The search will be significantly faster, especially as your glyph dataset grows.