picker

package
v0.0.0-...-df769fd Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package picker provides a simple best-match product picker for Frisco search results.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pick

func Pick(products []Product, phrase string, minScore float64) (Product, []Result, bool)

Pick finds the best-matching available product from products for the given search phrase.

Rules (in order of priority):

  1. Only available products are considered.
  2. Best match score wins.
  3. Ties broken by lowest PricePerKg (then lowest Price).

Returns (best, topN, ok).

  • ok is false when no available product scores >= minScore.
  • topN always contains up to 3 candidates (available, scored, sorted), even when ok is false, so callers can display them to the user.

func Score

func Score(productName, searchPhrase string) float64

Score returns a match score in [0,1] for a product name against a search phrase. It tokenises both strings (lowercase, split on whitespace) and counts what fraction of the query tokens appear in the name tokens.

Types

type Product

type Product struct {
	ProductID  string
	Name       string
	Brand      string
	Price      float64 // price per unit (from price.price)
	Grammage   string  // e.g. "500 g"
	PricePerKg float64 // price / weight in kg; 0 when unavailable
	Available  bool

	// raw entry so callers can pass it forward if needed
	Raw map[string]any
}

Product is a normalised view of a single product entry from the search API.

func NormaliseProducts

func NormaliseProducts(rawProducts []any) []Product

NormaliseProducts converts a raw products slice (as returned by the search API) into a slice of Product values.

type Result

type Result struct {
	Product Product
	Score   float64
}

Result pairs a product with its match score.

Jump to

Keyboard shortcuts

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