indexpolicy

package
v1.147.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package indexpolicy decides how a managed resource is indexed for search (#2111): fully, on its metadata alone, or not at all.

The decision is the writer's first. A writer that says nothing gets the default the operator's rules give the file, matched on its folder path, its media type, its size, its library scope and where the write came from; the first rule that matches decides. A rule may also set a ceiling, so a writer cannot ask for more indexing than the operator allows on a folder of bulk data. Being written by a script is never itself the deciding fact: poster art a pipeline writes is searchable, and an origin is only a matcher an operator may choose to use.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New(`must be one of "full", "metadata", "none"`)

ErrInvalid is returned for a policy value that is none of the three.

Functions

func MatchPath

func MatchPath(pattern, p string) bool

MatchPath reports whether a folder path matches a slash glob in which "**" stands for any number of folders, none included. Every other segment is a path.Match pattern.

func ParseSize

func ParseSize(s string) (int64, error)

ParseSize reads a whole number of bytes, or one with a unit (KiB, MiB, GiB, KB, MB, GB, B).

Types

type Config

type Config struct {
	// Default is the policy a resource no rule decides gets. Empty is full.
	Default string `yaml:"default,omitempty"`
	// Rules are matched in order; the first that sets an index decides the
	// default, and the first that sets a max caps a writer's request.
	Rules []Rule `yaml:"rules,omitempty"`
}

Config is the resources.index section.

func (Config) Resolver

func (c Config) Resolver() *Resolver

Resolver returns the resolver over c. A section is validated when the configuration loads, so one it cannot build is never asked for; the built-in rules answer if one is.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks every value the section names, so a typo is refused at startup rather than read as "no rule".

type Decision

type Decision struct {
	Policy   Policy
	Explicit bool
}

Decision is a resolved policy and whether the writer chose it. A policy no writer chose is the one a later reclassification may change.

type File

type File struct {
	Path      string
	MIMEType  string
	SizeBytes int64
	Scope     string
	Origin    Origin
}

File is what a rule is matched against.

type Origin

type Origin string

Origin is where a resource write came from, a matcher a rule may use.

const (
	// OriginUpload is a person uploading through the portal or the REST API.
	OriginUpload Origin = "upload"
	// OriginAgent is a session's manage_resource call.
	OriginAgent Origin = "agent"
	// OriginScript is any write made while a managed script runs.
	OriginScript Origin = "script"
	// OriginExport is an export tool's output landed in the library.
	OriginExport Origin = "export"
	// OriginWebhook is an inbound webhook source's compacted window.
	OriginWebhook Origin = "webhook"
)

The writers a resource can come from.

type Policy

type Policy string

Policy is how one resource is indexed for search.

const (
	Full     Policy = "full"
	Metadata Policy = "metadata"
	None     Policy = "none"
)

The three policies, cheapest last. Full embeds the resource's metadata and a prefix of its content and stores that prefix for the lexical arm; Metadata embeds the name, description, folder, filename and tags and reads no content; None enqueues no index job, reads no blob, stores no text and no vector.

func Parse

func Parse(s string) (Policy, error)

Parse reads a policy a writer or an operator named. Empty is not a policy; callers treat it as "not said".

func (Policy) Indexed

func (p Policy) Indexed() bool

Indexed reports whether a resource under p is given an index job at all.

func (Policy) ReadsContent

func (p Policy) ReadsContent() bool

ReadsContent reports whether a resource under p has its content extracted.

func (Policy) Valid

func (p Policy) Valid() bool

Valid reports whether p is one of the three policies.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver applies a validated Config.

func Default

func Default() *Resolver

Default returns a resolver with no operator rules: the built-in rules over a full default. A deployment that configures nothing gets it.

func NewResolver

func NewResolver(cfg Config) (*Resolver, error)

NewResolver builds a resolver over cfg, validating it. The built-in rules follow cfg's own.

func (*Resolver) Resolve

func (r *Resolver) Resolve(f File, requested Policy) Decision

Resolve decides f's policy. requested is what the writer asked for; empty is "not said". A request above the ceiling the first capping rule sets is lowered to that ceiling, and is still the writer's choice.

type Rule

type Rule struct {
	// Path is a slash glob over the resource's folder path, where "**"
	// matches any number of folders: "pipelines/**" is everything filed under
	// pipelines, at any depth.
	Path string `yaml:"path,omitempty"`
	// MIME lists media types, each exact or a family ("image/*").
	MIME []string `yaml:"mime,omitempty"`
	// SizeOver matches a file larger than this ("1MiB", "500KB", or bytes).
	SizeOver string `yaml:"size_over,omitempty"`
	// Scope matches the library: global, persona or user.
	Scope string `yaml:"scope,omitempty"`
	// Origin lists the writers the rule applies to.
	Origin []string `yaml:"origin,omitempty"`
	// Index is the policy a writer that says nothing gets. Empty leaves the
	// default to the next rule, so a rule may set only a ceiling.
	Index string `yaml:"index,omitempty"`
	// Max is the most indexing a writer may ask for here. Empty is no ceiling.
	Max string `yaml:"max,omitempty"`
	// contains filtered or unexported fields
}

Rule is one operator rule. Every matcher it sets must hold for the rule to apply; a rule that sets none applies to every resource.

func BuiltinRules

func BuiltinRules() []Rule

BuiltinRules are the rules that follow an operator's own: a table of values is embedded on its metadata alone, which is what #1988 did in code. An operator rule that matches first decides instead.

Jump to

Keyboard shortcuts

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