Reference Entry
What Querylight TS Covers
Overview · foundation · order 20
A compact browser and Node.js search toolkit for structured, explainable retrieval.
Relevant APIs
What Querylight TS Covers
Querylight TS is a pure TypeScript search toolkit for browsers and Node.js. It combines text retrieval, structured boolean queries, multi-field search, phrase search, prefix expansion, aggregations, vector search, geo search, and portable index state under one API.
In practical terms, that means you can use one local library to power very different kinds of search experiences:
- a docs search box with highlighting and BM25 ranking
- faceted or filtered discovery over structured metadata
- “Ask the Docs” style semantic search over chunked content
- related-article or recommendation features using vector similarity
- geo-aware retrieval for map or region-based content
That breadth is the main reason to use Querylight TS instead of a narrower fuzzy-only library.
If you are new to search tooling, the easiest mental model is:
- A
DocumentIndexstores your documents. - Each
TextFieldIndexindexes one field such astitle,body, ortags. - A query object describes what you want to match.
searchRequest(...)returns scored hits as[id, score]tuples.
Why it is broader than a fuzzy-only library
- It indexes structured fields instead of only flat strings.
- It supports both TF-IDF and BM25 ranking.
- It exposes
BoolQuerywithshould,must,filter,mustNot, andminimumShouldMatch. - It includes dedicated
PrefixQuery,TermsQuery,ExistsQuery, andMultiMatchQuerybuilding blocks. - It supports terms aggregations and significant terms for discovery.
- It includes
VectorFieldIndexandGeoFieldIndexfor non-lexical retrieval.
Common problems it can solve
If you are evaluating fit, these are the most common “jobs” Querylight TS can cover:
- Site search and docs search:
TextFieldIndex,MatchQuery,MultiMatchQuery, BM25, and highlighting. - Semantic search for help centers or docs:
VectorFieldIndex, chunking, andVectorRescoreQuery. - Related content and recommendations: vector similarity over articles, pages, or chunks.
- Faceted navigation:
BoolQuery, terms aggregations, and metadata fields such as tags, section, or product. - Typo-tolerant discovery:
prefix queries, ngram analyzers, and
bigramVector. - Geo-filtered search:
GeoFieldIndex,GeoPointQuery, andGeoPolygonQuery.
Minimal setup
import { DocumentIndex, MatchAll, TextFieldIndex } from "@tryformation/querylight-ts";
const index = new DocumentIndex({
title: new TextFieldIndex(),
body: new TextFieldIndex()
});
index.index({
id: "intro",
fields: {
title: ["Querylight TS"],
body: ["Portable search for browser and Node.js"]
}
});
const hits = index.searchRequest({ query: new MatchAll(), limit: 10 });
Expected result:
[
["intro", 1]
]
That 1 is the score for the matching document. Scores are mainly useful for ordering results. The important part is that the hit tells you which document matched.
What the result ids are for
Search returns ids first, not your full source objects. That keeps the index compact and lets you decide how to store and render your actual documents.
Typical pattern:
const sourceDocuments = new Map([
["intro", { title: "Querylight TS", url: "/docs/intro" }]
]);
const hits = index.searchRequest({ query: new MatchAll(), limit: 10 });
const results = hits.map(([id, score]) => ({
...sourceDocuments.get(id),
score
}));
Expected result:
[
{
title: "Querylight TS",
url: "/docs/intro",
score: 1
}
]
Common next steps
- Add more fields such as
summary,tags, orapi. - Replace
MatchAllwithMatchQuery,MatchPhrase, orBoolQuery. - Use aggregations to build facets from the current result set.
- Add vectors for semantic search or related-content features.
- Serialize the index at build time and load it in the browser.
More guides
- Choosing a Schema for Search
- Analyzer and Tokenization Deep Dive
- How To Build Autocomplete
- How To Build Faceted Navigation
- Relevance Tuning with BM25, TF-IDF, and RRF
- Document Chunking Strategies
- Serialization, Hydration, and Shipping Indexes
- Performance and Memory Tuning
- Testing Search Behavior
- Real-World Recipes
- Other Work Related to Querylight TS
- Comparing Querylight TS to Other Browser Search Libraries