Documentation
¶
Index ¶
- Constants
- type Column
- type Config
- type Engine
- func (e *Engine) BatchDelete(ctx context.Context, ids []string) error
- func (e *Engine) BatchList(ctx context.Context, compareColumn string, wantedCols []string, ...) (rows []ListResult, nextToken string, err error)
- func (e *Engine) BatchUpsert(ctx context.Context, docs map[string]map[string]string) error
- func (e *Engine) Close() error
- func (e *Engine) Delete(ctx context.Context, id string) error
- func (e *Engine) IsEmpty(ctx context.Context) (bool, error)
- func (e *Engine) Search(ctx context.Context, query string, pageToken string, pageSize int) (hits []SearchResult, nextToken string, err error)
- func (e *Engine) Upsert(ctx context.Context, id string, vals map[string]string) error
- type GetPrevCmp
- type Iterate
- type ListResult
- type Option
- type ProcessFile
- type SearchResult
- type SyncDecision
- type SyncStats
Constants ¶
const ( MemoryDBBaseDir = ":memory:" ColNameExternalID = "externalid" ColNameRowID = "rowid" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Column ¶
type Column struct {
// SQL identifier.
Name string `json:"name"`
// Stored but not tokenised.
Unindexed bool `json:"unindexed"`
// Bm25 weight (0 is treated as 1).
Weight float64 `json:"weight"`
}
Column declares one FTS5 column.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) BatchList ¶
func (e *Engine) BatchList( ctx context.Context, compareColumn string, wantedCols []string, pageToken string, pageSize int, ) (rows []ListResult, nextToken string, err error)
BatchList pages over the whole table ordered by `compareColumn` + rowid. If compareColumn == "" it falls back to ordering by rowid only (fast path). WantedCols limits the data that is returned to the caller. The slice must be a subset of cfg.Columns. Nil / empty means "all".
Returns rows, an opaque nextToken ("" == no more rows) and an error.
func (*Engine) BatchUpsert ¶
BatchUpsert writes / updates all docs inside ONE transaction. The map key is the externalID, the value is the column map.
func (*Engine) Search ¶
func (e *Engine) Search( ctx context.Context, query string, pageToken string, pageSize int, ) (hits []SearchResult, nextToken string, err error)
Search executes an FTS5 query with pagination. If more results exist, an opaque token is returned for the next page. The tokens are bound to the query string. The raw query string is cleaned to an OR-joined token list:
- Non-alphanumeric characters are ignored.
- Single-letter non-digit tokens are dropped.
- Duplicate tokens are removed.
type GetPrevCmp ¶
GetPrevCmp allows producers to query the compareColumn value that is currently stored for a specific ID ("" == not indexed yet).
type Iterate ¶
type Iterate func(getPrev GetPrevCmp, emit func(SyncDecision) error) error
Iterate is the generic producer contract. GetPrev lets the producer look at the current compareColumn value. Emit(dec) must be invoked exactly once for every document that belongs to this dataset.
type ListResult ¶
type ListResult struct {
// String id stored in the ColNameExternalID column.
ID string
Values map[string]string
}
ListResult is returned by BatchList().
type Option ¶
type Option func(*Engine)
Option is a functional option for configuring the FTSEngine.
func WithLogger ¶
WithLogger adds a logger to use for the fts engine.
type ProcessFile ¶
type ProcessFile func( ctx context.Context, baseDir, fullPath string, getPrev GetPrevCmp, ) (SyncDecision, error)
ProcessFile is the directory-walker callback.
type SearchResult ¶
type SyncDecision ¶
type SyncDecision struct {
// External identifier (rowid in the virtual table).
// Must be non-empty f Skip == false.
ID string
// Value for compareColumn (mtime / hash / ...). Ignored when Unchanged.
CmpOut string
// Column -> text map for FTS. Ignored when Unchanged.
Vals map[string]string
// The row is already up-to-date, nothing to do.
Unchanged bool
// Ignore this document entirely (also triggers delete if it existed).
Skip bool
}
type SyncStats ¶
type SyncStats struct {
TimeTaken time.Duration
Processed int
Upserted int
Unchanged int
Skipped int
Deleted int
}
func SyncDirToFTS ¶
func SyncIterToFTS ¶
func SyncIterToFTS( ctx context.Context, engine *Engine, compareColumn string, batchSize int, iter Iterate, belongs func(id string) bool, ) (stats *SyncStats, err error)
SyncIterToFTS. Belongs(id) must return true for all rows owned by this producer so that vanished rows can be deleted.