Documentation
¶
Index ¶
Constants ¶
const ( MinSlugLengthForFuzzy = 5 FuzzyMatchMaxLengthDiff = 2 FuzzyMatchMinSimilarity = 0.85 )
Shared thresholds keep title discovery and launch resolution aligned.
Variables ¶
This section is empty.
Functions ¶
func FindTokenSignatureMatches ¶
func FindTokenSignatureMatches( mediaType slugs.MediaType, queryName string, candidates []database.MediaTitle, ) []string
FindTokenSignatureMatches finds candidates where the token signature exactly matches the query signature. This enables word-order independent matching: "Crystal Space Quest" matches "Quest Space Crystal".
The query and candidates must have word boundaries (e.g., "Super Mario World"), not slugs. The mediaType ensures consistent parsing between query and indexed candidates. Returns the slugs of matched titles.
func FuzzyLengthWindow ¶ added in v2.18.0
FuzzyLengthWindow is how far a candidate slug's length may sit from the query's before it is discarded without being scored.
slack widens it upwards only, for a query that may have lost an abbreviation expansion to a typo: slug normalisation turns "Super Mario Bros." into "supermariobrothers" (18) while the typo "Super Mario Bross" stays "supermariobross" (15), so the title the user meant sits three characters away and a flat window of two threw it out unscored. Expansion only ever lengthens, so the lower bound does not move.
The widening is deliberately not unconditional. Applying it to every query measured 26ms to 531ms per lookup on the MiSTer test device against 24,000 titles, because the length bounds prune whole candidate blocks before any of them is read.
func GenerateTokenSignature ¶
GenerateTokenSignature creates a normalized, sorted token signature for word-order independent matching. Uses the same tokenization pipeline as slugification to ensure consistency.
IMPORTANT: Requires input with word boundaries (e.g., "Super Mario World"), not slugs. Slugs have already lost word boundary information and will produce incorrect signatures.
The mediaType parameter ensures media-type-specific parsing is applied (e.g., ParseGame for games), matching the indexing pipeline used in GenerateSlugWithMetadata.
Example:
GenerateTokenSignature(slugs.MediaTypeGame, "Super Mario World") → "mario_super_world" GenerateTokenSignature(slugs.MediaTypeGame, "Mario World Super") → "mario_super_world"
Types ¶
type FuzzyMatch ¶
FuzzyMatch represents a slug that matches the query with a similarity score.
func ApplyDamerauLevenshteinTieBreaker ¶
func ApplyDamerauLevenshteinTieBreaker(query string, matches []FuzzyMatch, topN int) []FuzzyMatch
ApplyDamerauLevenshteinTieBreaker refines fuzzy matches using Damerau-Levenshtein distance to handle transposition errors (e.g., "crono tigger" → "Chrono Trigger").
It takes the top N candidates from Jaro-Winkler and re-ranks them by edit distance. This two-stage approach is more accurate than either algorithm alone while remaining fast.
func FindFuzzyMatches ¶
func FindFuzzyMatches(query string, candidates []string, maxDistance int, minSimilarity float32) []FuzzyMatch
FindFuzzyMatches returns slugs that fuzzy match the query using Jaro-Winkler similarity. Jaro-Winkler is optimized for short strings and heavily weights matching prefixes, making it ideal for game titles where users typically get the start correct. It also naturally handles British/American spelling variations (e.g., "colour" vs "color"). Results are filtered by maxDistance and minSimilarity, sorted by similarity (best first).