Documentation
¶
Overview ¶
Package libraryfilter evaluates owner catalogue visibility rules without network access. The same compiled conditions drive local previews and every client. Rules run top to bottom and the first match wins. An empty action is hide, and an empty default is show, so a saved exclusion list hides the same titles as before.
These helpers support offline acceptance tests across package boundaries. Runtime callers use the production APIs in the other files.
Index ¶
- Variables
- func AppendPluginFacetClauses(where *strings.Builder, args *[]any, facets map[string][]string, ...)
- func CountryAliases(v string) []string
- func IsInvalidFilter(err error) bool
- func MarkInvalidFilter(err error) error
- func ParseDateDecadeBucket(id string) (int64, int64, bool)
- func ParseDateYearBucket(id string) (int64, int64, bool)
- func ParseDecadeBucket(id string) (int, int, bool)
- func ParseDurationBucket(id string) (int64, int64, bool)
- func PreviewableRules(specs []core.LibraryExclusion) (kept []core.LibraryExclusion, indices []int)
- func RegisterMediaTypeMigration(component string, version int, table, column, key string)
- func SplitDateDecadeFacet(key string) (string, bool)
- type BrowseCompiler
- type DurationBucketDef
- type Filter
- func Compile(specs []core.LibraryExclusion) (*Filter, error)
- func CompileLibraryPolicies(movies []core.LibraryExclusion, movieFallback string, ...) (*Filter, error)
- func CompilePluginPolicy(specs []core.LibraryExclusion, fallback string, declared map[string]string) (*Filter, error)
- func CompilePolicy(specs []core.LibraryExclusion, fallback string) (*Filter, error)
- func (f *Filter) BindCatalogue(compile func(core.Filter) (string, []any, error), ...) (*Filter, error)
- func (f *Filter) CatchCountsSQL() (string, []any)
- func (f *Filter) Decidable(t *core.Title) bool
- func (f *Filter) Facts() core.TitleFacts
- func (f *Filter) Fallback() string
- func (f *Filter) FallbackForType(typ core.MediaType) string
- func (f *Filter) ForSearch() *Filter
- func (f *Filter) Hidden(t *core.Title) bool
- func (f *Filter) MatchedHideRule(t *core.Title) (hidden bool, index int, byFallback bool)
- func (f *Filter) Passive() bool
- func (f *Filter) PluginCatchCountsSQL(typ core.MediaType, fields map[string]string) (string, []any)
- func (f *Filter) PluginSQLHidden(typ core.MediaType, fields map[string]string) (string, []any)
- func (f *Filter) RuleName(index int) string
- func (f *Filter) SQLHidden() (string, []any)
- func (f *Filter) SQLHiddenForType(typ core.MediaType) (string, []any)
- func (f *Filter) SQLShown() (string, []any)
- func (f *Filter) SQLUndecidable() string
- type InvalidFilterError
Constants ¶
This section is empty.
Variables ¶
var DurationBucketDefs = []DurationBucketDef{ {ID: "under-10m", Label: "Under 10 min", Min: 0, Max: 599}, {ID: "10-30m", Label: "10-30 min", Min: 600, Max: 1799}, {ID: "30-60m", Label: "30-60 min", Min: 1800, Max: 3599}, {ID: "1-2h", Label: "1-2 h", Min: 3600, Max: 7199}, {ID: "over-2h", Label: "Over 2 h", Min: 7200, Max: math.MaxInt64}, }
DurationBucketDefs are the canonical discrete duration facet buckets.
Functions ¶
func AppendPluginFacetClauses ¶
func AppendPluginFacetClauses(where *strings.Builder, args *[]any, facets map[string][]string, types map[string]string)
AppendPluginFacetClauses appends ` AND EXISTS (...)` (or envelope ` AND (...)`) predicates on plugin_item_fields / plugin_items for each facet key to where. Multiple values within a key combine with OR; multiple keys combine with AND.
func CountryAliases ¶
TMDB movie production countries use names; TV origins use ISO codes. Match both forms, never infer a country from the spoken language.
func IsInvalidFilter ¶
IsInvalidFilter reports whether err came from an invalid visibility rule or policy.
func MarkInvalidFilter ¶
MarkInvalidFilter wraps err as an InvalidFilterError when non-nil.
func ParseDateDecadeBucket ¶
ParseDateDecadeBucket resolves a decade bucket ("1990" or "1990s") into inclusive UTC Unix second bounds covering all 10 years of the decade.
func ParseDateYearBucket ¶
ParseDateYearBucket resolves a 4-digit UTC year bucket ("2024") into inclusive Unix second bounds [Jan 1 00:00:00 UTC, Dec 31 23:59:59 UTC].
func ParseDecadeBucket ¶
ParseDecadeBucket resolves a decade bucket ("1990" or "1990s") into inclusive [startYear, endYear] bounds (e.g. [1990, 1999]).
func ParseDurationBucket ¶
ParseDurationBucket resolves a duration bucket ID ("under-10m", "10-30m", ...) to its inclusive [min, max] second bounds.
func PreviewableRules ¶
func PreviewableRules(specs []core.LibraryExclusion) (kept []core.LibraryExclusion, indices []int)
PreviewableRules omits unfinished conditions and rule groups (such as a newly added rule whose values have not been chosen yet) while preserving malformed rules so the compiler still rejects invalid input. indices maps each returned rule back to its position in specs.
func RegisterMediaTypeMigration ¶
RegisterMediaTypeMigration upgrades component-owned rule documents once on both SQLite and PostgreSQL. Arguments are trusted schema identifiers.
func SplitDateDecadeFacet ¶
SplitDateDecadeFacet splits a "<dateField>-decade" synthetic facet key into its underlying declared date field key.
Types ¶
type BrowseCompiler ¶
BrowseCompiler validates a kind's field and compiles its indexed predicate.
type DurationBucketDef ¶
type DurationBucketDef struct {
ID string
Label string
Min int64
Max int64 // inclusive; math.MaxInt64 means unbounded upper end
}
DurationBucketDef describes a discrete duration facet bucket (seconds).
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
func Compile ¶
func Compile(specs []core.LibraryExclusion) (*Filter, error)
Compile treats every rule as hide and leaves unmatched titles visible.
func CompileLibraryPolicies ¶
func CompileLibraryPolicies(movies []core.LibraryExclusion, movieFallback string, shows []core.LibraryExclusion, showFallback string) (*Filter, error)
CompileLibraryPolicies compiles the canonical Movies (library 1) and TV Shows (library 2) policies into a single Filter used across all client protocols and the console. Each library may independently hold up to 32 rules and its own default visibility ("show" or "hide").
func CompilePluginPolicy ¶
func CompilePluginPolicy(specs []core.LibraryExclusion, fallback string, declared map[string]string) (*Filter, error)
CompilePluginPolicy rejects catalogue-only conditions instead of silently treating an unsupported plugin condition as a non-match. declared maps the kind's indexed field keys to their declared types; nil means the library's kind is unknown, so only built-in conditions compile. It takes plain types, not the plugin declaration, so this package never imports internal/plugins.
func CompilePolicy ¶ added in v0.3.0
func CompilePolicy(specs []core.LibraryExclusion, fallback string) (*Filter, error)
CompilePolicy compiles ordered rules. fallback is "show" or "hide" for titles that match nothing; empty means show.
func (*Filter) BindCatalogue ¶
func (f *Filter) BindCatalogue(compile func(core.Filter) (string, []any, error), evaluate func(string, []any, *core.Title) bool) (*Filter, error)
BindCatalogue compiles compound conditions using the catalogue's indexed browse compiler. It returns a copy; shared policies remain immutable.
func (*Filter) CatchCountsSQL ¶ added in v0.3.0
CatchCountsSQL returns one movie count and one show count per rule, in order. A title is counted on the first rule it matches.
func (*Filter) Decidable ¶
Decidable reports whether every condition of every hide rule that applies to t's type can be judged from t's own fields. A condition on an unknown field (no certification, countries, genres...) answers "no match", so a hide rule silently lets such a title through. An unknown field in a show rule can only make a title hidden, never shown, so show rules don't count. Callers that must fail closed (a restricted viewer's rules on a summary the catalogue has no details for) drop titles that are not decidable. Known/unknown conditions and vote counts (0 is a real value) are always decidable.
func (*Filter) Facts ¶
func (f *Filter) Facts() core.TitleFacts
Facts reports the facts outside a title's row that the rules read (core.TitleFacts): genres, studios and networks, countries, keywords. Every other condition is on the row itself.
func (*Filter) FallbackForType ¶
FallbackForType returns "show" or "hide" for the given media type.
func (*Filter) ForSearch ¶ added in v0.3.2
ForSearch returns the filter explicit searches use: the same rules without the ones scoped to discovery. Only hide rules carry that scope, so a title visible while browsing is never hidden from search. Compile it once per config change; it shares the compiled conditions.
func (*Filter) MatchedHideRule ¶
MatchedHideRule evaluates f's ordered rules against t and reports whether t is hidden, along with the matching hide rule's index (index >= 0) or byFallback == true when no rule matched and the default visibility is hide.
func (*Filter) PluginCatchCountsSQL ¶
PluginCatchCountsSQL counts the first matching rule for each plugin item.
func (*Filter) PluginSQLHidden ¶
PluginSQLHidden compiles the same ordered policy against plugin_items AS i. fields maps the rule vocabulary onto declared, indexed plugin field keys.
func (*Filter) SQLHidden ¶
SQLHidden returns a parameterized predicate for catalog_titles AS t. Hide-only rules with a show default stay an OR, which is the same predicate as first-match. A show rule or a hide default compiles to a CASE so the first match wins.
func (*Filter) SQLHiddenForType ¶ added in v0.3.4
SQLHiddenForType specializes the policy for a known media type. This retains first-match ordering while dropping rules for other media types.
func (*Filter) SQLShown ¶
SQLShown keeps a single allow rule sargable: its indexed predicates appear directly in WHERE rather than inside an ordered CASE. More involved policy orderings retain the general first-match compiler.
func (*Filter) SQLUndecidable ¶
SQLUndecidable is Decidable's complement for catalog_titles AS t: true when some condition of an applicable hide rule is on a field the row does not know. "0=1" when every row is decidable.
type InvalidFilterError ¶
type InvalidFilterError struct {
Err error
}
InvalidFilterError marks rule validation or compilation failures so HTTP handlers can report 400 instead of 500 regardless of library kind.
func (*InvalidFilterError) Error ¶
func (e *InvalidFilterError) Error() string
func (*InvalidFilterError) Unwrap ¶
func (e *InvalidFilterError) Unwrap() error