docs_search/lib.rs
1//! docs-search: the client-side search index for docs sites
2//! (docs-core extension program, `SPEC.md` REQ-Q).
3//!
4//! A serialized index is a single binary blob: an FST term dictionary whose
5//! values are offsets into a postings area of roaring bitmaps, plus a
6//! document-length table for BM25-shaped scoring. The whole API is
7//! bytes-in/bytes-out, so the same artifact serves a native compiler
8//! writing it and a browser runtime (wasm32) querying it.
9//!
10//! ```
11//! use docs_search::{IndexBuilder, Index};
12//!
13//! let mut b = IndexBuilder::new();
14//! b.add_doc("the quick brown fox");
15//! b.add_doc("the lazy dog");
16//! let bytes = b.build().unwrap();
17//!
18//! let idx = Index::from_bytes(&bytes).unwrap();
19//! let hits = idx.query("fox", 10);
20//! assert_eq!(hits.len(), 1);
21//! assert_eq!(hits[0].doc, 0);
22//! ```
23//!
24//! # Scope (0.1, honest)
25//!
26//! In: boolean AND queries, BM25-shaped ranking with unit term frequency
27//! (postings are presence bitmaps; frequency counts are deferred, and the
28//! ranking documents that), deterministic serialization, total decoding.
29//! Out: phrase queries, field weights, positional postings, and the
30//! quantized-vector section (REQ-Q1 keeps it behind a feature flag; it
31//! lands in a later 0.x, not silently: it is absent from the format's
32//! flag word until then).
33//!
34//! # Layer
35//!
36//! L0 - leaf. Zero estate-internal dependencies; external floor is
37//! `fst`, `roaring`, `thiserror`.
38
39#![deny(missing_docs)]
40#![forbid(unsafe_code)]
41
42mod error;
43mod format;
44mod index;
45
46pub use error::IndexError;
47pub use index::{Hit, Index, IndexBuilder};
48
49/// The crate's version, for callers that report it.
50pub const VERSION: &str = env!("CARGO_PKG_VERSION");