Documentation
¶
Overview ¶
Package search implements the text analyzer behind full-text search: the pipeline that turns field text and query strings into the terms the match evaluator and the search index agree on.
The TypeScript client (client/src/search/) implements the identical pipeline; cross-language conformance vectors live in testdata/search/vectors.json. Term-for-term agreement between the two is the contract that makes a locally executed match and a server-executed match return the same rows, so every stage is defined without reference to locale, ICU, or any other environment-dependent tables:
- Unicode NFKC normalization, so full-width forms, ligatures and compatibility characters compare equal to their plain spellings.
- Unicode full lowercase (Default Case Conversion, no locale), the mapping JavaScript's String.prototype.toLowerCase applies.
- Unless Options.KeepDiacritics is set: NFD, drop the combining marks of the Combining Diacritical Marks block (U+0300–U+036F), NFC. The range restriction folds Latin, Greek and Cyrillic accents while leaving scripts whose marks carry meaning — Thai, Devanagari, Hebrew, Arabic — untouched.
- Segmentation. Runs of letters, digits and combining marks form one term each, capped at 64 code points. Code points in the CJK ranges below instead form runs emitted as character bigrams (a one-character run is emitted as is), which makes text in scripts written without word separators searchable without a dictionary.
The CJK ranges are fixed by this package rather than taken from Unicode script tables: U+3005–U+3007, U+3040–U+30FF (Hiragana, Katakana), U+3400–U+4DBF, U+4E00–U+9FFF, U+F900–U+FAFF, U+20000–U+2FA1F (Han), U+AC00–U+D7A3 (Hangul syllables).
A term's position is its index in the returned slice; scoring measures proximity as index distance.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// KeepDiacritics disables the diacritic fold, so "café" and "cafe"
// analyze to distinct terms.
KeepDiacritics bool
}
Options configure analysis. The zero value is the default analyzer, and what a schema that sets no analyzer options gets.
type QueryTerm ¶
type QueryTerm struct {
Term string
// Prefix marks a term that matches any indexed term it prefixes rather
// than only itself. Only the final term of a query can carry it, and only
// when the query ends in the term itself — a trailing space or other
// separator makes the final term exact.
Prefix bool
}
QueryTerm is one term of an analyzed query string.
func AnalyzeQuery ¶
AnalyzeQuery returns the terms of a query string, in order, with the final term marked as a prefix when the query ends inside it. It returns nil for a query that yields no terms.