facet

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package facet defines the category-specific ad attributes (price, mileage, hours, year, condition, ...) in one typed registry. Each facet's kind, unit handling, allowed values, validation, and display formatting live in a single Def so that adding a facet is a one-line registry entry rather than a schema/SQL/UI change.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Def

type Def struct {
	Key        string
	Label      string
	Kind       Kind
	Form       FormWidget
	Filter     FilterWidget
	Units      []string // Int-only: allowed units stored in Value.Text; empty = no unit
	Suffix     string   // Int-only: constant suffix when Units is empty (e.g. "hrs")
	Compact    bool     // Int-only: render large values as e.g. "45K" on cards
	Enum       []string // enum options for FormSelect and FormRadio
	SelectMin  int      // FormSelect lower bound when Kind == Int (inclusive)
	SelectMax  int      // FormSelect upper bound when Kind == Int; 0 = current calendar year + 1
	Filterable bool     // show as a search filter pill
	Required   bool     // required on the new-ad form
}

Def is the definition of a single facet.

func All

func All() []Def

All returns every registered facet definition.

func Get

func Get(key string) (Def, bool)

Get returns the definition for a facet key.

func (Def) CardLabel

func (d Def) CardLabel() bool

CardLabel reports whether this facet appears after the title on listing cards.

func (Def) EmbeddingSnippet

func (d Def) EmbeddingSnippet(v Value) string

EmbeddingSnippet returns a prompt line for vector encoding.

func (Def) FormDefaultCurrency

func (d Def) FormDefaultCurrency(defaults FormDefaults) string

FormDefaultCurrency returns the selected currency for a money facet.

func (Def) FormDefaultUnit

func (d Def) FormDefaultUnit(defaults FormDefaults) string

FormDefaultUnit returns the selected unit for a facet with Units.

func (Def) FormOptions

func (d Def) FormOptions() []string

FormOptions returns dropdown or checkbox choices for form widgets.

func (Def) FormatCompact

func (d Def) FormatCompact(v Value) string

FormatCompact renders a value for dense contexts (listing cards).

func (Def) FormatFull

func (d Def) FormatFull(v Value) string

FormatFull renders a value with full precision (ad detail page).

func (Def) LocationPlaceholder

func (d Def) LocationPlaceholder() string

LocationPlaceholder returns the form placeholder for a Location facet.

func (Def) NormalizeUnit

func (d Def) NormalizeUnit(unit string) string

NormalizeUnit returns unit if allowed, otherwise the first allowed unit.

func (Def) SelectBounds

func (d Def) SelectBounds() (min, max int)

SelectBounds returns inclusive min/max for FormSelect on Kind Int.

func (Def) SupportedCurrencies

func (d Def) SupportedCurrencies() []string

SupportedCurrencies returns currency dropdown options for money facets.

func (Def) ValidFilterValue

func (d Def) ValidFilterValue(val string) bool

ValidFilterValue reports whether val is an allowed search filter option.

func (Def) ValidUnit

func (d Def) ValidUnit(unit string) bool

ValidUnit reports whether unit is allowed for this facet.

func (Def) Validate

func (d Def) Validate(v Value) error

Validate checks a value against the definition. Optional facets may be absent; Required facets must be present and pass kind-specific rules.

func (Def) VectorMetadataValue

func (d Def) VectorMetadataValue(v Value) (any, bool)

VectorMetadataValue returns the JSONB value for search filters.

type Filter

type Filter struct {
	Min    *int     `json:"min,omitempty"`
	Max    *int     `json:"max,omitempty"`
	Value  *string  `json:"value,omitempty"`
	Values []string `json:"values,omitempty"`
}

Filter is a search constraint. Min/Max apply to Int and Money. Value is one selection. Values holds multiple Enum selections (OR within the facet).

func (Filter) Active

func (f Filter) Active() bool

type FilterWidget

type FilterWidget int

FilterWidget controls the search filter pill for a facet.

const (
	FilterRange      FilterWidget = iota // min/max inputs
	FilterCheckboxes                     // multi-select (Enum checkboxes)
	FilterFlag                           // single opt-in checkbox (Flag)
)

type FormDefaults

type FormDefaults struct {
	Currency string // default selected currency for money facets
	Unit     string // preferred unit for facets with Units (e.g. mi/km)
}

FormDefaults holds per-request values for new-ad form widgets.

type FormWidget

type FormWidget int

FormWidget controls the new-ad form control for a facet.

const (
	FormNumber   FormWidget = iota // plain number input (+ unit select when Units set)
	FormSelect                     // <select>; options from Enum (Kind Enum) or SelectMin..SelectMax (Kind Int)
	FormRadio                      // exclusive choices for Kind Enum
	FormMoney                      // amount + currency + FREE
	FormLocation                   // location text input (Kind Location)
	FormFlag                       // single opt-in checkbox (Kind Flag)
)

type Kind

type Kind int
const (
	Int      Kind = iota // numeric, range-filterable
	Money                // amount + currency (Value.Text), FREE when amount == 0
	Enum                 // fixed string set, exact-match filter
	Location             // user location text; resolves to ads.location_id
	Flag                 // optional opt-in; Num == 1 when set
)

type Value

type Value struct {
	Num  *int
	Text *string
}

Value is a stored facet value for one ad. Num holds Int/Money amounts; Text holds currency (Money), unit (Int with Units), or the selection (Enum).

func EncodeFlag

func EncodeFlag(checked bool) Value

EncodeFlag builds a Flag value when checked.

func (Value) FlagSet

func (v Value) FlagSet() bool

FlagSet reports whether a Flag facet value is checked.

func (Value) Present

func (v Value) Present() bool

Jump to

Keyboard shortcuts

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