FuzzyMatcher
Fuzzy matching utilities. The PHP port of pi-tui's `fuzzy.ts`. A query matches a text when all of its characters appear in order (not necessarily consecutive). A lower score is a better match. The score rewards consecutive matches and word-boundary hits, penalizes gaps, and breaks ties toward earlier matches — so typing `mtch` ranks `match` above `mat_tooth` even though both match. `fuzzyFilter()` takes a list of items, a query, and a text extractor, and returns the items whose text matches every whitespace/slash- separated token of the query, sorted best-first. This is what a `SelectList` filter, a command palette, or an autocomplete dropdown uses to rank results. The secondary "swap digits/letters" fallback from pi-tui is preserved so `4u` still matches `for you` (alpha-numeric swap). Pure utility, no dependencies — safe to call from any renderer or test.
FuzzyMatcher::match()
public static function match(string $query, string $text): arrayWhether `$query` fuzzy-matches `$text` and, if so, how good the match is. Lower score = better. Returns `{matches: false, score: 0}` when there is no match.
Parameters
| Name | Type | Description |
|---|---|---|
| $query | string | |
| $text | string |
FuzzyMatcher::filter()
public static function filter(array $items, string $query, callable $getText): arrayThe items whose text fuzzily matches the query, best match first.
Parameters
| Name | Type | Description |
|---|---|---|
| $items | array<int, mixed> | |
| $query | string | |
| $getText | callable(mixed): string |