Reef Search Documentation
Welcome to the official documentation for Reef Search. This guide covers everything from basic installation to advanced configuration and integration.
What is Reef Search?
Reef Search is a zero-build, client-side search overlay designed for static websites. It transforms a simple <script> tag into a powerful, keyboard-first search experience that indexes your content entirely in the visitor's browser.
Key Characteristics
- Zero backend required — No servers, no database, no external API calls
- Privacy-first — All indexing and search happens locally in the browser
- Framework agnostic — Works with plain HTML, React, Vue, Svelte, or any framework
- Keyboard-first UX — Press ⌘K or Ctrl+K to open the search modal
- Small footprint — Approximately 6.2KB gzipped (excluding fonts)
Core Philosophy
Reef Search was built on the principle that static sites deserve better search without the complexity. Traditional search solutions require:
- Account registration and dashboard configuration
- Server-side indexing and query processing
- Monthly fees based on usage volume
- Privacy concerns as all queries are logged
Reef Search eliminates all of these requirements while providing a search experience that rivals hosted solutions.
How It Works: Architecture Deep Dive
System Architecture
Reef Search consists of four main components working in harmony:
1. Loader (loader.ts)
Entry point that reads configuration from script attributes, registers the Cmd+K/Ctrl+K hotkey, and initializes the search system during browser idle time.
2. Crawler/Indexer (search.ts)
Discovers pages via sitemap.xml, fetches content via fetch API, and extracts searchable content using DOMParser.
3. Index Store (search.ts)
In-memory search index with optimized data structures for fast querying. Supports multiple record types with weighted scoring.
4. UI Layer (reef.ts)
Shadow DOM-based modal overlay with keyboard navigation, result rendering, and action execution capabilities.
Initialization Flow
When you include Reef Search on a page, the following sequence occurs:
- Script Load — The browser downloads
reef.min.jsfrom your server or CDN - Configuration Parse — The loader reads
data-*attributes from the script tag - Hotkey Registration — Listens for ⌘K/Ctrl+K to open the modal
- Sitemap Fetch (if available) — Retrieves
sitemap.xmlto discover all pages - Parallel Page Fetching — Fetches up to 6 pages concurrently (configurable via
data-max-pages) - Content Extraction — Parses each page's HTML and extracts headings, body text, and other content types
- Index Building — Tokenizes all content into an in-memory search index
- User Interaction — Search queries run against the in-memory index with fuzzy matching
Data Structures
The search index uses three primary data structures for efficient querying:
// headingIds: Map<string, IndexRecord[]>
// Stores records indexed by exact heading text (lowercase)
// Example: "installation" → [record1, record2]
// headingIndex: Map<string, IndexRecord[]>
// Stores records indexed by heading text prefixes
// Enables fast prefix matching for autocomplete-style search
// bodyIndex: Map<string, IndexRecord[]>
// Stores records indexed by individual body text words (3+ chars)
// Used for full-text search within page content
Universal Record Types
Overview
Reef Search supports seven distinct record types, each with specific extraction rules and interaction behaviors:
| Type | Icon | Description | Behavior |
|---|---|---|---|
section |
📄 | Page headings and their associated body text | Navigate to page and scroll to heading anchor |
action |
⚡ | Clickable elements: buttons, toggles, summaries | Execute click event on current page, or navigate with deferred execution |
field |
📝 | Form inputs, textareas, and select elements | Focus the element (and select its content) |
link |
🔗 | External links (different origin than current page) | Navigate to the linked page |
file |
📎 | Downloadable resources (PDF, DOC, XLS, etc.) | Navigate to download the file |
media |
🎵 | Images with alt text and video/audio with transcripts | Navigate and highlight the media element |
structured |
🔍 | FAQ entries and other JSON-LD structured data | Navigate to the FAQ or structured data location |
Scoring Algorithm
Search results are ranked using weighted scoring based on match type:
| Match Type | Score | Description |
|---|---|---|
| Exact heading match | 100 | Perfect match on heading text |
| Heading prefix match | 50 | Query matches beginning of heading |
| Body word match | 20 | Query appears in section body text |
| Fallback substring | 40 / 10 | Substring match in heading/body as last resort |
Destructive Action Detection
Actions with labels containing certain keywords are treated as destructive and excluded from automatic execution:
const destructiveVerbs = [
'delete', 'remove', 'cancel subscription', 'unsubscribe',
'pay', 'checkout', 'submit order', 'confirm'
];
When an action is marked destructive, the search will navigate to the page instead of executing immediately, allowing the user to confirm the action visually.
Use Cases
Documentation Sites
The primary use case for Reef Search is documentation websites. It excels at:
- Searching across hundreds of pages of documentation
- Navigating directly to specific API references or examples
- Finding configuration options without knowing exact names
Blog Search
For personal blogs and articles, Reef Search enables:
- Full-text search across all articles
- Searching by topic tags or keywords
- Finding related content through fuzzy matching
Knowledge Bases
Internal or external knowledge bases benefit from:
- Instant search results without backend queries
- Indexing FAQ structured data for direct answers
- Finding procedures documented across many pages
E-commerce Product Search
Small catalog sites can use Reef Search for:
- Searching product names and descriptions
- Filtering by product attributes
- Privacy-first search (no analytics leakage)
Dashboard Action Search
⚠️ Important Security Note
When using action indexing on interactive sites, Reef Search provides:
- Searching for buttons and UI controls by their labels
- Executing safe actions directly from the search modal
- Navigating to pages to run destructive actions safely
Quick Start
Ready to add search to your site? Here's the fastest path:
<script src="https://unpkg.com/reef-search/dist/reef.min.js"></script>
That's it. Reef Search will automatically:
- Look for
/sitemap.xmlat your site root - Fetch and index all pages listed in the sitemap
- Open the search modal when users press ⌘K or Ctrl+K
Having trouble? Installation guide → covers troubleshooting, CDN options, and framework-specific setups.