Documentation
¶
Overview ¶
Package search is ContentKit's keyword retrieval over content_search_documents: exact names and aliases, native-script prefixes and bounded typos for every language, with the visibility join (Eligibility) applied inside every route.
Index ¶
- Constants
- func DeleteKeywordDocuments(ctx context.Context, db Executor, schema string, keys []DocumentKey) error
- func EligibilityJoin(e *Eligibility, args pgx.NamedArgs) (join, priority string, err error)
- func MarkDirty(ctx context.Context, db Executor, schema string, marks []DirtyMark) error
- func QuoteSchema(schema string) (string, error)
- func UpsertKeywordDocuments(ctx context.Context, db Executor, schema string, docs []KeywordDocument) error
- type Candidate
- type DirtyMark
- type DocumentKey
- type Eligibility
- type Executor
- type Hit
- type KeywordDocument
- type Options
- type RRFContribution
- type RRFHit
- type RRFKey
- type RRFOptions
- type RRFTraceHit
- type RRFTraceKey
- type Result
Constants ¶
const MaxCandidateLimit = 10_000
MaxCandidateLimit bounds one route's document window.
Variables ¶
This section is empty.
Functions ¶
func DeleteKeywordDocuments ¶
func DeleteKeywordDocuments(ctx context.Context, db Executor, schema string, keys []DocumentKey) error
DeleteKeywordDocuments removes the documents; unknown keys are ignored.
func EligibilityJoin ¶
func EligibilityJoin(e *Eligibility, args pgx.NamedArgs) (join, priority string, err error)
EligibilityJoin renders the eligibility query as the lateral join every route applies to a candidate row aliased sd, binding its named args. It returns the join clause (empty without eligibility) and the priority expression to select.
func MarkDirty ¶
MarkDirty queues documents for the worker, in the transaction that changes their records; the queue trigger assigns each row a new revision.
func QuoteSchema ¶
QuoteSchema validates and quotes a schema identifier for embedding in SQL.
func UpsertKeywordDocuments ¶
func UpsertKeywordDocuments(ctx context.Context, db Executor, schema string, docs []KeywordDocument) error
UpsertKeywordDocuments derives every lexical projection from structured input for a batch of documents of any tenant, kind or language.
Types ¶
type Candidate ¶
type Candidate struct {
contentref.ContentRef
Language string
Score float32
}
Candidate is one document proposed by another retrieval source.
type DirtyMark ¶
type DirtyMark struct {
DocumentKey
Deleted bool
Reason string
}
DirtyMark asks the worker to rebuild (or delete) one document.
type DocumentKey ¶
type DocumentKey struct {
contentref.ContentRef
Language string
}
DocumentKey identifies one keyword document: a content reference in one language. The language is metadata of the document, never of the content.
type Eligibility ¶
Eligibility is ContentKit's own SQL (the discovery routes' rendering of the visibility rule) joined laterally to every candidate document (alias sd: tenant_id, content_kind, content_id, content_version_id, language). It returns no row when the document is not eligible for this request, or one row with the column priority (integer: preferred document among a content item's equal matches, lower first). Ownership, access, publication and every requested version trait must hold on that one row; sibling documents never make each other eligible.
type Hit ¶
type Hit struct {
contentref.ContentRef
Language string
// Priority orders same-item documents at equal match; lower is preferred.
Priority int32
Score float32
}
Hit is one matched document.
func Eligible ¶
func Eligible(ctx context.Context, pool *pgxpool.Pool, opts Options, candidates []Candidate) ([]Hit, error)
Eligible returns the candidates that exist as documents of the request tenant and language and pass the eligibility join, in their input order with Priority filled. Candidates another source proposes are never trusted with eligibility: this is the same join every keyword route runs.
type KeywordDocument ¶
type KeywordDocument struct {
DocumentKey
Title string
Aliases []string
Keywords []string
}
KeywordDocument is the search input for one document, built by ContentKit from its own records. Derived search text belongs to ContentKit; callers never write it. An empty Title deletes the document. Aliases are alternate names; Keywords are contextual terms (for example trusted tags), not descriptions.
func (KeywordDocument) Validate ¶ added in v0.58.4
func (d KeywordDocument) Validate() error
Validate checks a document before it crosses into the keyword index. An empty title is a deletion, so only its key needs validation.
type Options ¶
type Options struct {
Schema string
Tenant string
Language string
// ContentKinds limits the kinds searched; empty means every kind.
ContentKinds []string
Limit int
// Eligibility binds pgx '@name' placeholders other than the reserved
// tenant, language, q, prefix, limit, kinds and candidates.
Eligibility *Eligibility
}
Options selects one tenant, language and window of a keyword request.
type RRFContribution ¶
type RRFHit ¶
func FuseRRF ¶
func FuseRRF(lists [][]RRFKey, opts RRFOptions) []RRFHit
FuseRRF fuses multiple ranked lists (best-first) into one ranked list.
type RRFKey ¶
type RRFKey struct {
contentref.ContentKey
Language string
}
RRFKey identifies one document across fused lists.
type RRFOptions ¶
type RRFOptions struct {
// K is the stabilizer constant; higher K flattens rank differences.
// Defaults to 60 when <= 0.
K int
// Finite weights apply to each list; missing weights default to 1.
// Zero excludes a list. Negative weights subtract its contributions.
Weights []float32
}
RRF (Reciprocal Rank Fusion) combines ranked lists without relying on raw score calibration: score(doc) = Σ weight_i / (k + rank_i), rank 1-based.
type RRFTraceHit ¶
type RRFTraceHit struct {
Hit RRFHit `json:"-"`
Key RRFTraceKey `json:"key"`
Score float32 `json:"score"`
Contributions []RRFContribution `json:"contributions"`
}
func FuseRRFWithTrace ¶
func FuseRRFWithTrace(lists [][]RRFKey, opts RRFOptions) ([]RRFTraceHit, error)
FuseRRFWithTrace returns the same ordered hits as FuseRRF plus the exact source-list contributions used to compute each score.
type RRFTraceKey ¶
type Result ¶
type Result struct {
// Hits are documents ordered by score, content kind, content id and version.
Hits []Hit
// Truncated reports that a route filled its SQL window or that more scored
// documents existed than Limit: documents beyond the window were never ranked.
Truncated bool
}
Result is one language's scored document window.
func KeywordSearch ¶
func KeywordSearch(ctx context.Context, pool *pgxpool.Pool, query string, opts Options) (Result, error)
KeywordSearch preserves names and aliases, including native scripts. Exact names precede aliases, token/prefix matches, then conservative one-edit typos. PostgreSQL retrieves bounded candidates; Go never scans the document catalog. The eligibility join runs inside every route before its limit.