Documentation
¶
Overview ¶
Package query holds pure query-layer string functions: term parsing, FTS5 query sanitizing, stopword stripping, boolean-operator translation, and the path / min-messages predicates. No dependencies beyond the standard library.
The FTS5 sanitizer neutralizes SQLite FTS5 operators so a plain-English query can't accidentally invoke FTS5 syntax.
Index ¶
- Variables
- func BooleanToFTS5(raw string) (fts5Expr string, usedOperators bool)
- func HasSearchableToken(q string) bool
- func MakeSnippet(text string, terms []string) (snippet string, ok bool)
- func MinMessagesOK(messageCount, minimum int) bool
- func ParseTerms(q string) []string
- func PathPredicate(include, exclude string) func(cwd string) bool
- func SanitizeFTS5Query(q string) string
- func StripStopwords(q string) string
Constants ¶
This section is empty.
Variables ¶
var Stopwords = map[string]struct{}{
"a": {}, "an": {}, "the": {}, "of": {}, "to": {}, "in": {}, "on": {},
"for": {}, "and": {}, "or": {}, "not": {}, "near": {}, "is": {}, "are": {},
"was": {}, "were": {}, "be": {}, "it": {}, "its": {}, "this": {}, "that": {},
"with": {}, "as": {}, "at": {}, "by": {}, "we": {}, "i": {}, "you": {},
"do": {}, "did": {}, "what": {}, "where": {}, "when": {}, "how": {}, "our": {},
"your": {}, "from": {}, "about": {},
}
Stopwords are common words + FTS5 boolean keywords dropped from natural- language queries. A set for O(1) membership.
Functions ¶
func BooleanToFTS5 ¶
BooleanToFTS5 translates human boolean operators (&&→AND, ||→OR, !term→NOT term, quoted phrases, parentheses) into an FTS5 MATCH expression.
CRUCIAL INVARIANT: if `raw` contains NO boolean operators, the returned expr is EXACTLY SanitizeFTS5Query(raw) and usedOperators is false (plain queries stay byte-identical).
func HasSearchableToken ¶
HasSearchableToken reports whether the query has any token that is not a bare AND/OR/NOT keyword.
func MakeSnippet ¶
MakeSnippet rebuilds a human-readable snippet from matched (tool-stripped) text, highlighting `terms` with >>>...<<<. Returns ("", false) if no term is present in the human text (the match was tool-only) — the bool reports presence.
func MinMessagesOK ¶
MinMessagesOK reports whether messageCount >= minimum.
func ParseTerms ¶
ParseTerms splits a query into lowercased phrases (quoted) + bare terms, dropping AND/OR/NOT boolean keywords and trailing '*' wildcards.
func PathPredicate ¶
PathPredicate returns a predicate filtering a transcript cwd string against optional include/exclude regexes. A bad regex degrades to literal substring containment (never panics). Pass "" for include or exclude to skip that filter.
func SanitizeFTS5Query ¶
SanitizeFTS5Query neutralizes FTS5 syntax hazards in a plain-English query: protects quoted phrases, drops structural chars, tames wildcards, strips a leading/trailing boolean keyword, and quotes path-like / dotted-hyphenated identifiers so FTS5 keeps each as one searchable phrase.
func StripStopwords ¶
StripStopwords drops Stopwords tokens from a query while preserving quoted phrases untouched. A quoted phrase may carry an attached prefix-'*' (e.g. SanitizeFTS5Query turns `self-update*` into `"self-update"*`), so the sentinel can be embedded in a token rather than standing alone — it is restored in place after the stopword filter, never dropped as a bare NUL.
Types ¶
This section is empty.