PHPackages                             designbycode/fuzzy-search - 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. [Search &amp; Filtering](/categories/search)
4. /
5. designbycode/fuzzy-search

ActiveLibrary[Search &amp; Filtering](/categories/search)

designbycode/fuzzy-search
=========================

The Fuzzy Search package provides a simple and efficient way to perform fuzzy searches on a collection of texts using the Levenshtein distance algorithm. This package is useful when you need to search for texts that may contain typos or slight variations.

v1.0.3(1y ago)09[1 PRs](https://github.com/designbycode/fuzzy-search/pulls)MITPHPPHP ^8.1|^8.2|^8.3

Since Jul 20Pushed 1y agoCompare

[ Source](https://github.com/designbycode/fuzzy-search)[ Packagist](https://packagist.org/packages/designbycode/fuzzy-search)[ Docs](https://github.com/designbycode/fuzzy-search)[ GitHub Sponsors](https://github.com/Designbycode)[ RSS](/packages/designbycode-fuzzy-search/feed)WikiDiscussions main Synced yesterday

READMEChangelog (4)Dependencies (4)Versions (6)Used By (0)

Fuzzy Search
============

[](#fuzzy-search)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ffdbee5af175259a9f237d3a6f1ebfc328d040e09b3e7097b6d562ed10654ecb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64657369676e6279636f64652f66757a7a792d7365617263682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/designbycode/fuzzy-search)[![Tests](https://camo.githubusercontent.com/1350623adc42ccd25511da6adedc716d2905af29c00ec3bca6cc32dc22884a90/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f64657369676e6279636f64652f66757a7a792d7365617263682f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/designbycode/fuzzy-search/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/cb7f889fa523e70f6d0fa7251b42e09d3af915b3d0f682d9c37b17ef46b5fec5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64657369676e6279636f64652f66757a7a792d7365617263682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/designbycode/fuzzy-search)

Introduction
------------

[](#introduction)

The Fuzzy Search package provides a simple and efficient way to perform fuzzy searches on a collection of texts using the Levenshtein distance algorithm. This package is useful when you need to search for texts that may contain typos or slight variations.

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

[](#installation)

To install the Fuzzy Search package, simply require it in your PHP project using Composer:

```
composer require designbycode/fuzzy-search
```

Usage
-----

[](#usage)

### Creating a Fuzzy Search Instance

[](#creating-a-fuzzy-search-instance)

To create a Fuzzy Search instance, you need to pass an array of texts to search and an optional flag for case-insensitive search:

```
use Designbycode\FuzzySearch\FuzzySearch;

$texts = ['apple', 'banana', 'orange', 'grape'];
$fuzzySearch = new FuzzySearch($texts, true); // Case-insensitive search
```

Performing a Fuzzy Search
-------------------------

[](#performing-a-fuzzy-search)

To perform a fuzzy search, call the `search` method and pass the search query and an optional maximum Levenshtein distance:

```
$query = 'aple';
$maxDistance = 2;
$results = $fuzzySearch->search($query, $maxDistance);
print_r($results); // Output: ['apple']
```

The search method returns an array of matching texts, sorted by their Levenshtein distance from the search query.

Getting the Best Match
----------------------

[](#getting-the-best-match)

To get the best match from the search results, call the getBestMatch method:

```
$bestMatch = $fuzzySearch->getBestMatch($results);
echo $bestMatch; // Output: 'apple'
```

Levenshtein Distance Calculator
-------------------------------

[](#levenshtein-distance-calculator)

The Levenshtein Distance Calculator is a utility class that calculates the Levenshtein distance between two strings. This class is used internally by the Fuzzy Search package.

### Calculating the Levenshtein Distance

[](#calculating-the-levenshtein-distance)

To calculate the Levenshtein distance between two strings, call the calculate method:

```
use Designbycode\FuzzySearch\LevenshteinDistance;

$str1 = 'kitten';
$str2 = 'sitting';
$distance = LevenshteinDistance::calculate($str1, $str2);
echo $distance; // Output: 3
```

Examples
--------

[](#examples)

### Example 1: Fuzzy Search with Case-Insensitive Search

[](#example-1-fuzzy-search-with-case-insensitive-search)

```
$texts = ['Apple', 'Banana', 'Orange', 'Grape'];
$fuzzySearch = new FuzzySearch($texts, true);

$query = 'aple';
$maxDistance = 2;
$results = $fuzzySearch->search($query, $maxDistance);
print_r($results); // Output: ['Apple']
```

### Example 2: Fuzzy Search with Case-Sensitive Search

[](#example-2-fuzzy-search-with-case-sensitive-search)

```
$texts = ['apple', 'banana', 'orange', 'grape'];
$fuzzySearch = new FuzzySearch($texts, false);

$query = 'Aple';
$maxDistance = 2;
$results = $fuzzySearch->search($query, $maxDistance);
print_r($results); // Output: []
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Claude Myburgh](https://github.com/designbycode)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90% 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.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

713d ago

PHP version history (2 changes)v1.0.0PHP ^8.1

v1.0.2PHP ^8.1|^8.2|^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6057076?v=4)[Claude Myburgh](/maintainers/claudemyburgh)[@claudemyburgh](https://github.com/claudemyburgh)

---

Top Contributors

[![claudemyburgh](https://avatars.githubusercontent.com/u/6057076?v=4)](https://github.com/claudemyburgh "claudemyburgh (9 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

searchfuzzy-searchlevenshteinlevenshtein-distancedesignbycode

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/designbycode-fuzzy-search/health.svg)

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

###  Alternatives

[elasticsearch/elasticsearch

PHP Client for Elasticsearch

5.3k187.3M1.1k](/packages/elasticsearch-elasticsearch)[teamtnt/tntsearch

A fully featured full text search engine written in PHP

3.2k3.2M30](/packages/teamtnt-tntsearch)[ruflin/elastica

Elasticsearch Client

2.3k52.4M229](/packages/ruflin-elastica)[solarium/solarium

PHP Solr client

93334.5M118](/packages/solarium-solarium)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15528.5M116](/packages/opensearch-project-opensearch-php)[rap2hpoutre/similar-text-finder

Fuzzy Search, similar text finder: "Did you mean `foo` ?"

14477.9k3](/packages/rap2hpoutre-similar-text-finder)

PHPackages © 2026

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