A high-performance document search engine built in Rust with WebAssembly support.
docfind
A high-performance document search engine built in Rust with WebAssembly support. Combines full-text search using FST (Finite State Transducers) with FSST compression for efficient storage and fast fuzzy matching capabilities.
Live Demo
Check out the interactive demo. The demo showcases docfind searching through 50,000 news articles from the AG News dataset, running entirely in your browser with WebAssembly.
The compiled binary will be available at ./target/release/docfind.
Usage
Creating a Search Index
Prepare a JSON file with your documents:
json
[{"title":"Getting Started","category":"docs","href":"/docs/getting-started","body":"This guide will help you get started."},{"title":"API Reference","category":"reference","href":"/docs/api","body":"Complete API documentation for all search functions and configuration options."}]
Build the index and generate a WASM module:
bash
docfind documents.json output
This creates:
output/docfind.js - JavaScript bindings
output/docfind_bg.wasm - WebAssembly module with embedded index
Using in the Browser
xml
How It Works
mermaid
flowchart LR
A([documents.json]) --> B[docfind]
B --> C[Keyword Extraction
RAKE]
B --> E[FSST Compression
document strings]
C --> D[FST Map
keywords → docs]
D --> F[[Index]]
E --> F
F --> G([docfind_bg.wasm
+ docfind.js])
style A fill:#e1f5ff
style G fill:#e1f5ff
style F fill:#ffffcc
Indexing Phase (CLI):
Extracts keywords from document titles, categories, and bodies
Uses RAKE algorithm to identify important multi-word phrases
Assigns relevance scores based on keyword source (metadata > title > body)
Builds an FST mapping keywords to document indices
Compresses all document strings using FSST
Serializes the index using Postcard (binary format)
Embedding Phase (CLI):
Parses the pre-compiled WASM module
Expands WASM memory to accommodate the index
Patches global variables (INDEX_BASE, INDEX_LEN) with actual values
Adds the index as a new data segment in the WASM binary
Search Phase (WASM):
Deserializes the embedded index on first use
Performs fuzzy matching using Levenshtein automaton
Combines results from multiple keywords with score accumulation
Decompresses matching document strings on demand
Returns ranked results as JavaScript objects
Dependencies
fst: Fast finite state transducer library with Levenshtein support