query

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 2 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func BooleanToFTS5(raw string) (fts5Expr string, usedOperators bool)

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

func HasSearchableToken(q string) bool

HasSearchableToken reports whether the query has any token that is not a bare AND/OR/NOT keyword.

func MakeSnippet

func MakeSnippet(text string, terms []string) (snippet string, ok bool)

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

func MinMessagesOK(messageCount, minimum int) bool

MinMessagesOK reports whether messageCount >= minimum.

func ParseTerms

func ParseTerms(q string) []string

ParseTerms splits a query into lowercased phrases (quoted) + bare terms, dropping AND/OR/NOT boolean keywords and trailing '*' wildcards.

func PathPredicate

func PathPredicate(include, exclude string) func(cwd string) bool

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

func SanitizeFTS5Query(q string) string

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

func StripStopwords(q string) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL