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 ¶
- func FormatDateRange(start, end string) string
- func SaleDateDetailDisplays(start, end string) []string
- func SaleWeekRange(preset string, now time.Time) (min, max time.Time, ok bool)
- 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 ¶
func FormatDateRange ¶
FormatDateRange renders a compact date or date range for listing cards.
func SaleDateDetailDisplays ¶
SaleDateDetailDisplays returns bullet labels for sale dates on the ad detail page.
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 in the search filter panel
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"`
TextMin *string `json:"text_min,omitempty"`
TextMax *string `json:"text_max,omitempty"`
Value *string `json:"value,omitempty"`
Values []string `json:"values,omitempty"`
}
Filter is a search constraint. Min/Max apply to Int/Money; TextMin/TextMax to Date; Value to a single Enum; Values to multiple Enum selections (OR within the facet).
func ResolveFilterForSearch ¶
ResolveFilterForSearch converts stored filter presets into query constraints.
type FilterWidget ¶
type FilterWidget int
FilterWidget controls the search filter panel for a facet.
const ( FilterRange FilterWidget = iota // min/max inputs FilterExact // single-select (Enum dropdown) 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 FormDate // date input (Kind Date) FormCheckboxes // multi-select checkboxes (Kind MultiEnum) 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 Date // ISO date YYYY-MM-DD in Value.Text MultiEnum // multiple enum selections, JSON array in Value.Text Location // user location text; resolves to ads.location_id Flag // optional opt-in; Num == 1 when set )
type Value ¶
Value is a stored facet value for one ad. Num holds Int/Money amounts; Text holds currency (Money), unit (Int with Units), selection (Enum/Date), or a JSON array (MultiEnum). Values holds decoded MultiEnum selections in memory.
func EncodeMultiEnum ¶
EncodeMultiEnum builds a MultiEnum value from selected options.
func ParseDateValue ¶
ParseDateValue parses an ISO date string into a Date facet value.
func (Value) DateString ¶
DateString returns the ISO date from a Date facet value.
func (Value) MultiEnumValues ¶
MultiEnumValues decodes MultiEnum selections from memory or stored JSON.