How We Built Blazing-Fast Full-Text Search
Search is at the heart of Snigo. When you have hundreds (or thousands) of code snippets, the ability to find the right one instantly is what separates a useful tool from a frustrating one. In this post, we'll take you behind the scenes of Quickfinder — our full-text search engine.
The Challenge
Code search is fundamentally different from text search. Developers expect:
- Results in real-time as they type (no "Search" button)
- Matching on code syntax, not just natural language
- Fuzzy matching for typos and partial queries
- Relevance ranking that understands code structure
Our Approach: Inverted Index + Trigram Matching
We use a combination of inverted indexing and trigram matching to achieve sub-50ms search times. When a snippet is saved, we tokenize its content into trigrams (3-character sequences) and store them in an inverted index.
When you search, we break your query into trigrams, look up matching documents, and score them based on trigram overlap, recency, and user interaction history.
Why Trigrams?
Traditional word-based indexing fails for code because code doesn't follow natural language word boundaries. Consider searching for useState — a word-based index might not match useStateValue, but trigram matching catches it instantly.
Performance Results
With our current architecture, search across 10,000 snippets completes in under 35ms on average. Even on mobile devices, results appear before the user finishes typing.
What's Next
We're experimenting with semantic search powered by code embeddings. Imagine searching for "sort an array of objects by date" and finding your custom comparator function — even if the snippet doesn't contain those exact words. Stay tuned.