PHPackages                             sugarcraft/candy-fuzzy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sugarcraft/candy-fuzzy

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sugarcraft/candy-fuzzy
======================

Fuzzy string matching with scored matched indices — Smith-Waterman + Sahilm algorithms. Unblocks filter-highlighting UI across the ecosystem.

02↓100%PHP

Since Jun 1Pushed 1w agoCompare

[ Source](https://github.com/sugarcraft/candy-fuzzy)[ Packagist](https://packagist.org/packages/sugarcraft/candy-fuzzy)[ RSS](/packages/sugarcraft-candy-fuzzy/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

CandyFuzzy
==========

[](#candyfuzzy)

Fuzzy string matching library with scored matched character indices — enables filter highlighting UI across the SugarCraft ecosystem.

Installation
------------

[](#installation)

```
composer require sugarcraft/candy-fuzzy
```

Role
----

[](#role)

Extracts the canonical Smith-Waterman fuzzy matcher from `candy-forms` and adds the key feature that was previously impossible: **ranked matches WITH scored matched character indices**, enabling UI filter highlighting.

Provides two algorithms:

- **SmithWatermanMatcher** — Smith-Waterman local alignment with adjacency bonus. Bit-equivalent to the original `candy-forms` implementation.
- **SahilmMatcher** — Ports the `sahilm/fuzzy` algorithm used by `charmbracelet/gum` filter. Includes separator bonus, camelCase bonus, exact-prefix bonus.

Quickstart
----------

[](#quickstart)

```
use SugarCraft\Fuzzy\Matcher\SmithWatermanMatcher;
use SugarCraft\Fuzzy\Highlighter;

$matcher = new SmithWatermanMatcher();

// Match a single candidate
$result = $matcher->match('foo', 'foobar');
// MatchResult(needle: 'foo', haystack: 'foobar', score: 16, matchedIndices: [0, 1, 2])

// Match against multiple candidates (sorted by score desc)
$results = $matcher->matchAll('app', ['apple', 'applet', 'application', 'apricot']);
// Returns list of MatchResult sorted by score

// Highlight matched runs
$highlighter = new Highlighter();
$styled = $highlighter->highlight($result, fn($matched) => "\033[1m$matched\033[0m");
// Returns 'foobar' with matched chars styled
```

MatchResult
-----------

[](#matchresult)

```
final class MatchResult
{
    public readonly string $needle;      // Search query
    public readonly string $haystack;   // Matched candidate
    public readonly int $score;         // Higher = better match
    public readonly array $matchedIndices; // 0-based char indices of matched chars
}
```

Interface
---------

[](#interface)

Swap matchers without touching call-sites:

```
use SugarCraft\Fuzzy\MatcherInterface;
use SugarCraft\Fuzzy\FuzzyMatcher;

function filter(MatcherInterface $matcher, string $query, array $candidates): array
{
    return $matcher->matchAll($query, $candidates);
}
```

Algorithm Differences
---------------------

[](#algorithm-differences)

FeatureSmithWatermanSahilmLocal alignment✅❌Adjacent bonus✅ (5)✅ (consecutive: 5)Separator bonus❌✅ (10)CamelCase bonus❌✅ (10)First-char bonus❌✅ (15)Case sensitive❌OptionalBackward Compatibility
----------------------

[](#backward-compatibility)

The existing `SugarCraft\Forms\Fuzzy\FuzzyMatcher` and `SugarCraft\Lister\FuzzyMatch` classes remain as deprecated shims that delegate to `SugarCraft\Fuzzy\Matcher\SmithWatermanMatcher`. Consumers will migrate in subsequent steps.

Links
-----

[](#links)

- [Smith-Waterman algorithm](https://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm)
- [sahilm/fuzzy (Go)](https://github.com/sahilm/fuzzy)
- [charmbracelet/bubbletea](https://github.com/charmbracelet/bubbletea)

[![codecov](https://camo.githubusercontent.com/76124539d9973d9af3266041e7e5fcdfa35afbe504313aa1d76fbf6d42ec88aa/68747470733a2f2f636f6465636f762e696f2f67682f737567617263726166742f63616e64792d66757a7a792f6272616e63682f6d61737465722f67726170682f62616467652e7376673f666c61673d63616e64792d66757a7a79)](https://codecov.io/gh/sugarcraft/candy-fuzzy)

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance64

Regular maintenance activity

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b1036e0717211b8030b83cbe729e8ba6ba442fdbd5285fb97a39d7dcfe339342?d=identicon)[detain](/maintainers/detain)

---

Top Contributors

[![detain](https://avatars.githubusercontent.com/u/1364504?v=4)](https://github.com/detain "detain (4 commits)")

### Embed Badge

![Health badge](/badges/sugarcraft-candy-fuzzy/health.svg)

```
[![Health](https://phpackages.com/badges/sugarcraft-candy-fuzzy/health.svg)](https://phpackages.com/packages/sugarcraft-candy-fuzzy)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
