Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultNormalizer = NewDefaultNormalizer()
DefaultNormalizer is a statically allocated default normalizer for strings.
Functions ¶
func NormalizeForMatching ¶ added in v1.10.0
NormalizeForMatching applies cached full normalization for cross-seed matching:
- Unicode normalization (removes diacritics, decomposes ligatures)
- Lowercase
- Strip apostrophes (including Unicode variants)
- Strip colons
- Convert ampersand to "and"
- Convert hyphens to spaces
- Collapse multiple spaces to single space
Results are cached per input string (5 minute TTL) to avoid repeated expensive transformations.
Examples:
- "Shōgun S01" → "shogun s01"
- "Bob's Burgers" → "bobs burgers"
- "CSI: Miami" → "csi miami"
- "Spider-Man" → "spider man"
- "His & Hers" → "his and hers"
func NormalizeUnicode ¶ added in v1.10.0
NormalizeUnicode removes diacritics and decomposes ligatures with caching. Results are cached per input string (5 minute TTL) to avoid repeated expensive transformations. For the full normalization with additional punctuation handling, use NormalizeForMatching instead. Examples:
- "Shōgun" → "Shogun"
- "Amélie" → "Amelie"
- "naïve" → "naive"
- "Björk" → "Bjork"
- "æ" → "ae"
- "fi" → "fi"
Types ¶
type Normalizer ¶
type Normalizer[K comparable, V any] struct { // contains filtered or unexported fields }
Normalizer caches transformed results so we do not repeatedly transform the same inputs.
func NewDefaultNormalizer ¶
func NewDefaultNormalizer() *Normalizer[string, string]
NewDefaultNormalizer returns a normalizer using the default TTL and default transform (ToLower + TrimSpace).
func NewNormalizer ¶
func NewNormalizer[K comparable, V any](ttl time.Duration, transform TransformFunc[K, V]) *Normalizer[K, V]
NewNormalizer returns a normalizer with the provided TTL and transform function for cached entries.
func (*Normalizer[K, V]) Clear ¶
func (n *Normalizer[K, V]) Clear(key K)
Clear removes a cached entry.
func (*Normalizer[K, V]) Normalize ¶
func (n *Normalizer[K, V]) Normalize(key K) V
Normalize returns the transformed value.
type TransformFunc ¶
type TransformFunc[K, V any] func(K) V
TransformFunc is a function that transforms K to V.