Documentation
¶
Overview ¶
@index Shared search backend interface and errors for SQLite FTS5 and PostgreSQL tsvector implementations.
@index PostgreSQL tsvector + GIN based full-text search backend implementation (including schema, triggers, and queries).
@index Query sanitizers for backend-specific full-text search syntax.
@index SQLite FTS5 virtual table-based full-text search backend implementation (including migration, legacy upgrades, and incremental re-indexing).
Index ¶
- Variables
- func SanitizeFTS5(query string) string
- func SanitizePostgresTSQuery(query string) string
- type Backend
- type PostgresBackend
- func (p *PostgresBackend) Migrate(db *gorm.DB) error
- func (p *PostgresBackend) PurgeNamespace(ctx context.Context, db *gorm.DB) error
- func (p *PostgresBackend) Query(ctx context.Context, db *gorm.DB, query string, limit int) ([]model.Node, error)
- func (p *PostgresBackend) Rebuild(ctx context.Context, db *gorm.DB) error
- func (p *PostgresBackend) RebuildNodes(ctx context.Context, db *gorm.DB, nodeIDs []uint) error
- type SQLiteBackend
- func (s *SQLiteBackend) Migrate(db *gorm.DB) error
- func (s *SQLiteBackend) PurgeNamespace(ctx context.Context, db *gorm.DB) error
- func (s *SQLiteBackend) Query(ctx context.Context, db *gorm.DB, query string, limit int) ([]model.Node, error)
- func (s *SQLiteBackend) Rebuild(ctx context.Context, db *gorm.DB) error
- func (s *SQLiteBackend) RebuildNodes(ctx context.Context, db *gorm.DB, nodeIDs []uint) error
Constants ¶
This section is empty.
Variables ¶
var ErrFTS5NotAvailable = trace.New("fts5 module not available")
ErrFTS5NotAvailable indicates the SQLite build lacks the fts5 extension.
Functions ¶
func SanitizeFTS5 ¶
SanitizeFTS5 converts raw user input into a safe FTS5 prefix query. @intent build SQLite FTS queries that preserve prefix matching without exposing parser-breaking characters. @domainRule empty or fully stripped input returns an empty query string.
func SanitizePostgresTSQuery ¶
SanitizePostgresTSQuery converts raw user input into a safe prefix tsquery. @intent translate free-form user input into a PostgreSQL tsquery that mirrors the SQLite prefix search behavior. @domainRule empty or fully stripped input returns an empty query string.
Types ¶
type Backend ¶
type Backend interface {
// @intent prepare search tables and indexes for the active database driver.
// @sideEffect may create or update search index schema objects.
Migrate(db *gorm.DB) error
// @intent refresh backend-specific full-text index state from the current persisted search documents for the active namespace.
// @requires db must be a valid connection for processing the active namespace.
// @sideEffect rewrites backend-specific search index records or derived vectors.
Rebuild(ctx context.Context, db *gorm.DB) error
// @intent reindex only changed nodes so incremental updates cost less than full rebuilds.
// @param nodeIDs is the set of node IDs to reindex.
// @sideEffect updates search index records for the specified nodes.
RebuildNodes(ctx context.Context, db *gorm.DB, nodeIDs []uint) error
// @intent remove or reconcile backend-specific search index state for the active namespace when physical cleanup is required.
// @sideEffect may clear namespace-scoped search index records, though implementations may intentionally no-op.
PurgeNamespace(ctx context.Context, db *gorm.DB) error
// @intent execute a user query using the backend-specific full-text search syntax.
// @param query is the raw query string to search for.
// @param limit is the maximum number of results to return.
// @return returns nodes ordered by relevance.
Query(ctx context.Context, db *gorm.DB, query string, limit int) ([]model.Node, error)
}
Backend defines the full-text search backend contract. @intent provide one interface for backend-specific search index migration, rebuild, and query operations.
type PostgresBackend ¶
type PostgresBackend struct{}
PostgresBackend is a full-text search backend based on PostgreSQL tsvector. @intent Handles full-text search indexing and querying in a PostgreSQL environment.
func NewPostgresBackend ¶
func NewPostgresBackend() *PostgresBackend
NewPostgresBackend creates a PostgreSQL search backend. @intent Provides a Backend implementation specifically for PostgreSQL.
func (*PostgresBackend) Migrate ¶
func (p *PostgresBackend) Migrate(db *gorm.DB) error
Migrate prepares the PostgreSQL full-text search schema. @intent Sets up the tsvector-based search infrastructure on the search_documents table. @sideEffect Creates or replaces columns, indexes, trigger functions, and triggers. @ensures The tsv column is automatically updated when search_documents is modified.
func (*PostgresBackend) PurgeNamespace ¶
PurgeNamespace is a no-op as PostgreSQL search_documents deletion does not require separate physical cleanup. @intent Aligns with the Backend interface and maintains consistency in the workspace purge path.
func (*PostgresBackend) Query ¶
func (p *PostgresBackend) Query(ctx context.Context, db *gorm.DB, query string, limit int) ([]model.Node, error)
Query searches for related nodes using PostgreSQL tsquery. @intent Converts the user's search term into a prefix tsquery to find related nodes. @requires limit must be greater than 0 to get meaningful results. @return Returns a list of nodes sorted by ts_rank.
func (*PostgresBackend) Rebuild ¶
Rebuild recalculates the tsvector for all search documents. @intent Batch regenerates the full-text search index for existing search_documents rows. @sideEffect Updates search_documents.tsv values.
func (*PostgresBackend) RebuildNodes ¶
RebuildNodes recalculates the tsvector only for specified nodes. @intent Avoids full namespace tsv updates during incremental update paths.
type SQLiteBackend ¶
type SQLiteBackend struct {
// contains filtered or unexported fields
}
SQLiteBackend is a full-text search backend based on SQLite FTS5. @intent Handles full-text search indexing and querying in a SQLite environment.
func NewSQLiteBackend ¶
func NewSQLiteBackend() *SQLiteBackend
NewSQLiteBackend creates a SQLite search backend. @intent Provides a Backend implementation specifically for SQLite.
func (*SQLiteBackend) Migrate ¶
func (s *SQLiteBackend) Migrate(db *gorm.DB) error
Migrate prepares the SQLite FTS5 virtual table. @intent Creates a full-text search index table for SQLite. @sideEffect May create the search_fts virtual table. @ensures search_fts exists if FTS5 is available.
func (*SQLiteBackend) PurgeNamespace ¶
PurgeNamespace removes the physical FTS index for a specific namespace. @intent Cleans up stale FTS rows even in paths without a rebuild, such as workspace deletion.
func (*SQLiteBackend) Query ¶
func (s *SQLiteBackend) Query(ctx context.Context, db *gorm.DB, query string, limit int) ([]model.Node, error)
Query searches for related nodes using FTS5 MATCH queries. @intent Converts the user's search term into a SQLite FTS prefix query to find nodes. @requires limit must be greater than 0 to get meaningful results. @return Returns a list of nodes sorted by FTS rank.
func (*SQLiteBackend) Rebuild ¶
Rebuild reloads search_documents content into the FTS index. @intent Synchronizes stored search documents with the SQLite FTS index. @sideEffect Deletes and re-inserts search_fts content. @domainRule Index content must match the current snapshot of search_documents.
func (*SQLiteBackend) RebuildNodes ¶
RebuildNodes synchronizes only the FTS rows of specified nodes with search_documents. @intent Avoids full namespace FTS reloading during incremental update paths.