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 ¶
- type Def
- func (d Def) CardLabel() bool
- func (d Def) EmbeddingSnippet(v Value) string
- func (d Def) FormDefaultCurrency(defaults FormDefaults) string
- func (d Def) FormDefaultUnit(defaults FormDefaults) string
- func (d Def) FormOptions() []string
- func (d Def) FormatCompact(v Value) string
- func (d Def) FormatFull(v Value) string
- func (d Def) LocationPlaceholder() string
- func (d Def) NormalizeUnit(unit string) string
- func (d Def) SelectBounds() (min, max int)
- func (d Def) SupportedCurrencies() []string
- func (d Def) ValidFilterValue(val string) bool
- func (d Def) ValidUnit(unit string) bool
- func (d Def) Validate(v Value) error
- func (d Def) VectorMetadataValue(v Value) (any, bool)
- type Filter
- type FilterWidget
- type FormDefaults
- type FormWidget
- type Kind
- type Value
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 (Def) CardLabel ¶
CardLabel reports whether this facet appears after the title on listing cards.
func (Def) EmbeddingSnippet ¶
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 ¶
FormOptions returns dropdown or checkbox choices for form widgets.
func (Def) FormatCompact ¶
FormatCompact renders a value for dense contexts (listing cards).
func (Def) FormatFull ¶
FormatFull renders a value with full precision (ad detail page).
func (Def) LocationPlaceholder ¶
LocationPlaceholder returns the form placeholder for a Location facet.
func (Def) NormalizeUnit ¶
NormalizeUnit returns unit if allowed, otherwise the first allowed unit.
func (Def) SelectBounds ¶
SelectBounds returns inclusive min/max for FormSelect on Kind Int.
func (Def) SupportedCurrencies ¶
SupportedCurrencies returns currency dropdown options for money facets.
func (Def) ValidFilterValue ¶
ValidFilterValue reports whether val is an allowed search filter option.
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).
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) )