Reference Entry
WildcardQuery for Term-Level Pattern Matching
Lexical Querying · advanced · order 70
Match indexed terms with `*` and `?` patterns without switching to full-text analysis.
Relevant APIs
WildcardQuery for Term-Level Pattern Matching
WildcardQuery matches indexed terms using simple wildcard syntax:
*matches zero or more characters?matches exactly one character
This is a term-level query. It works against analyzed terms that already exist in the index.
Basic example
import { DocumentIndex, TextFieldIndex, WildcardQuery } from "@tryformation/querylight-ts";
const index = new DocumentIndex({
title: new TextFieldIndex()
});
index.index({ id: "1", fields: { title: ["querylight"] } });
index.index({ id: "2", fields: { title: ["query planner"] } });
index.index({ id: "3", fields: { title: ["vector search"] } });
const hits = index.searchRequest({
query: new WildcardQuery("title", "que*")
});
When to use it
- Match families of tags or codes.
- Support simple power-user patterns.
- Search normalized keyword-like values with a little flexibility.
Wildcard vs MatchQuery
MatchQueryanalyzes the input text and uses lexical ranking.WildcardQuerychecks indexed terms directly.
If you want normal search-box behavior, use MatchQuery.
If you want pattern matching over already-indexed terms, use WildcardQuery.
Notes
- Wildcards operate on analyzed terms, not raw source strings.
- Broad leading wildcards such as
*lightmay match many terms. - For simple prefix use cases,
PrefixQueryis usually clearer.