Documentation
¶
Overview ¶
Package search defines the full-text-search contract that backends (and, where supported, their transactions) implement. Backends opt into FTS by satisfying FTSProvider (which extends FTSSearcher with the registration-time setup hook); transactions implement only FTSSearcher because index/trigger creation is a one-time setup operation that does not belong on a transactional path.
Application code reaches FTS through QuerySet.Search at the den root — direct imports of this package are only needed when building a custom backend.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LiteralFTS5 ¶ added in v0.17.0
LiteralFTS5 turns a raw user term into a literal-terms FTS5 MATCH expression: each whitespace-separated token becomes a double-quoted literal (embedded quotes doubled), tokens joined by spaces so FTS5 ANDs them. This neutralises FTS5 operators and punctuation (AND/OR/NEAR, col:term scoping, prefix *, stray quotes) that would otherwise raise a syntax error or let a client scope columns. An all-blank term yields "".
The same string is safe to feed to PostgreSQL plainto_tsquery, which discards the quotes as punctuation and ANDs the surviving lexemes — so QuerySet.Search applies this once and dispatches the result to either backend unchanged.
Types ¶
type FTSProvider ¶
type FTSProvider interface {
FTSSearcher
EnsureFTS(ctx context.Context, collection string, fields []string) error
}
FTSProvider extends FTSSearcher with the registration-time setup hook. Backends implement the full interface; transactions implement only FTSSearcher because index/trigger creation is a one-time setup operation that does not belong on a transactional path.
EnsureFTS must be idempotent, and after it returns, rows that existed in the collection before the first call must be searchable — first-time setup backfills the index from existing data rather than indexing only subsequent writes.
type FTSSearcher ¶
type FTSSearcher interface {
Search(ctx context.Context, collection string, query string, q *backend.Query) (backend.Iterator, error)
}
FTSSearcher is the read-side full-text search contract. Both backends and transactions implement it so QuerySet.Search honors the caller's scope: `NewQuery[T](db).Search(...)` reads committed state, while `NewQuery[T](tx).Search(...)` sees the tx's uncommitted writes (the FTS index is updated in-tx by triggers on SQLite and by tsvector + GIN under MVCC on PostgreSQL).