PHPackages                             tantee/laravel-searchy-fork - 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. tantee/laravel-searchy-fork

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

tantee/laravel-searchy-fork
===========================

Laravel Searchy makes user driven searching easy with fuzzy search, basic string matching, Levenshtein Distance and more.

2.0.22(4y ago)03.3k1MITPHPPHP ^5.5.9 || ^7.0 || ^8.0

Since Jun 14Pushed 4y agoCompare

[ Source](https://github.com/tantee/laravel-searchy-folk)[ Packagist](https://packagist.org/packages/tantee/laravel-searchy-fork)[ RSS](/packages/tantee-laravel-searchy-fork/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (3)Versions (22)Used By (1)

Fork for Laravel 8 support
--------------------------

[](#fork-for-laravel-8-support)

Since the original Laravel-Searchy became unmaintenance. I forked it to make laravel 8 compatible by editing composer.json and necessary codes without any full testing, please use with caution.

The most of original code, namespace, function name are left untouched.

The original repo is here

Laravel 5+ Searchy
------------------

[](#laravel-5-searchy)

### Database Searching Made Easy

[](#database-searching-made-easy)

Searchy is an; easy-to-use, light-weight, MySQL only, Laravel package that makes running user driven searches on data in your models simple and effective. It uses pseudo fuzzy searching and other weighted mechanics depending on the search driver that you have enabled. It requires no other software installed on your server (so can be a little slower than dedicated search programs) but can be set up and ready to go in minutes.

#### !! Laravel 4 !!

[](#-laravel-4-)

Looking for Laravel 4 compatible Searchy? Checkout the 1.0 branch :)

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

[](#installation)

Add `"tom-lingham/searchy" : "2.*"` to your composer.json file under `require`:

```
"require": {
  "laravel/framework": "5.*",
  "tom-lingham/searchy" : "2.*"
}
```

Run `composer update` in your terminal to pull down the package into your vendors folder.

Add the service provider to the `providers` array in Laravel's `./config/app.php` file:

```
TomLingham\Searchy\SearchyServiceProvider::class
```

Add the Alias to the `aliases` array in Laravel's `./config/app.php` file if you want to have quick access to it in your application:

```
'Searchy' => TomLingham\Searchy\Facades\Searchy::class
```

Usage
-----

[](#usage)

To use Searchy, you can take advantage of magic methods.

If you are searching the name and email column/field of users in a `users` table you would, for example run:

```
$users = Searchy::users('name', 'email')->query('John Smith')->get();
```

You can also write this as:

```
$users = Searchy::search('users')->fields('name', 'email')->query('John Smith')->get();
```

In this case, pass the columns you want to search through to the `fields()` method.

These examples both return an array of Objects containing your search results. You can use `getQuery()` instead of `get()` to return an instance of the Database Query Object in case you want to do further manipulation to the results:

```
$users = Searchy::search('users')->fields('name', 'email')->query('John Smith')
    ->getQuery()->having('relevance', '>', 20)->get();
```

### Limit on results returned

[](#limit-on-results-returned)

To limit your results, you can use Laravel's built in DatabaseQuery Builder method and chain further methods to narrow your results.

```
// Only get the top 10 results
$users = Searchy::search('users')->fields('name', 'email')->query('John Smith')
    ->getQuery()->limit(10)->get();
```

### Searching multiple Columns

[](#searching-multiple-columns)

You can also add multiple arguments to the list of fields/columns to search by.

For example, if you want to search the name, email address and username of a user, you might run:

```
$users = Searchy::users('name', 'email', 'username')->query('John Smith')->get();
```

If you need to build your table list dynamically, you can also pass an array of fields instead as the first argument (All other following arguments will be ignored):

```
$users = Searchy::users(['name', 'email', 'username'])->query('John Smith')->get();
```

### Searching Joined/Concatenated Columns

[](#searching-joinedconcatenated-columns)

Sometimes you may want to leverage searches on concatenated column. For example, on a `first_name` and `last_name` field but you only want to run the one query. To do this can separate columns with a double colon:

```
$users = Searchy::users('first_name::last_name')->query('John Smith')->get();
```

### Soft Deleted Records

[](#soft-deleted-records)

By default soft deletes will not be included in your results. However, if you wish to include soft deleted records you can do so by adding the `withTrashed()` after specifying your table and fields;

```
Searchy::users('name')->withTrashed()->query('Batman')->get();
```

### Return only specific columns

[](#return-only-specific-columns)

You can specify which columns to return in your search:

```
$users = Searchy::users('first_name::last_name')->query('John Smith')->select('first_name')->get();

// Or you can swap those around...
$users = Searchy::users('first_name::last_name')->select('first_name')->query('John Smith')->get();
```

This will, however, also return the `relevance` aliased column regardless of what is entered here.

How to get a Laravel Eloquent Collection
----------------------------------------

[](#how-to-get-a-laravel-eloquent-collection)

Transforming the search results into a collection of Laravel Eloquent models is outside the scope of this project. However, an easy way to achieve this without hitting your database more than necessary is to use the Eloquent `hydrate()` method.

```
\App\User::hydrate(Searchy::users('name', 'email')->query('Andrew')->get());
```

This method creates a collection of models from a plain arrays. This is just our case because Searchy results are provided as arrays, and using `hydrate` we will converted them to instances of `User` model.

Unicode Characters Support
--------------------------

[](#unicode-characters-support)

If you are having issues with the returned results because you have unicode characters in your search data, you can use the `FuzzySearchUnicodeDriver`.

*PLEASE NOTE: There is no sanitization of strings passed through to the `FuzzySearchUnicodeDriver` prior to inserting into raw MySQL statements. You will have to sanitize the string yourself first or risk opening up your application to SQL injection attacks. You have been warned.*

To use, first follow the instructions to publish your configuration file (`php artisan vendor:publish`) and change your default driver from `fuzzy` to `ufuzzy`.

```
return [

    'default' => 'ufuzzy',

  ...
]
```

Configuration
-------------

[](#configuration)

You can publish the configuration file to your `app` directory and override the settings by running `php artisan vendor:publish` to copy the configuration to your config folder as `searchy.php`

You can set the default driver to use for searches in the configuration file. Your options (at this stage) are: `fuzzy`, `simple` and `levenshtein`.

You can also override these methods using the following syntax when running a search:

```
Searchy::driver('fuzzy')->users('name')->query('Batman')->get();
```

Drivers
-------

[](#drivers)

Searchy takes advantage of 'Drivers' to handle matching various conditions of the fields you specify.

Drivers are simply a specified group of 'Matchers' which match strings based on specific conditions.

Currently there are only three drivers: Simple, Fuzzy and Levenshtein (Experimental).

### Simple Search Driver

[](#simple-search-driver)

The Simple search driver only uses 3 matchers each with the relevant multipliers that best suited my testing environments.

```
protected $matchers = [
  'TomLingham\Searchy\Matchers\ExactMatcher'                 => 100,
  'TomLingham\Searchy\Matchers\StartOfStringMatcher'         => 50,
  'TomLingham\Searchy\Matchers\InStringMatcher'              => 30,
];
```

### Fuzzy Search Driver

[](#fuzzy-search-driver)

The Fuzzy Search Driver is simply another group of matchers setup as follows. The multipliers are what I have used, but feel free to change these or roll your own driver with the same matchers and change the multipliers to suit.

```
protected $matchers = [
  'TomLingham\Searchy\Matchers\ExactMatcher'                 => 100,
  'TomLingham\Searchy\Matchers\StartOfStringMatcher'         => 50,
  'TomLingham\Searchy\Matchers\AcronymMatcher'               => 42,
  'TomLingham\Searchy\Matchers\ConsecutiveCharactersMatcher' => 40,
  'TomLingham\Searchy\Matchers\StartOfWordsMatcher'          => 35,
  'TomLingham\Searchy\Matchers\StudlyCaseMatcher'            => 32,
  'TomLingham\Searchy\Matchers\InStringMatcher'              => 30,
  'TomLingham\Searchy\Matchers\TimesInStringMatcher'         => 8,
];
```

### Levenshtein Search Driver (Experimental)

[](#levenshtein-search-driver-experimental)

The Levenshtein Search Driver uses the Levenshetein Distance to calculate the 'distance' between strings. It requires that you have a stored procedure in MySQL similar to the following `levenshtein( string1, string2 )`. There is an SQL file with a suitable function in the `res` folder - feel free to use this one.

```
protected $matchers = [
  'TomLingham\Searchy\Matchers\LevenshteinMatcher' => 100
];
```

Matchers
--------

[](#matchers)

### ExactMatcher

[](#exactmatcher)

Matches an exact string and applies a high multiplier to bring any exact matches to the top.

### StartOfStringMatcher

[](#startofstringmatcher)

Matches Strings that begin with the search string. For example, a search for 'hel' would match; 'Hello World' or 'helping hand'

### AcronymMatcher

[](#acronymmatcher)

Matches strings for Acronym 'like' matches but does NOT return Studly Case Matches For example, a search for 'fb' would match; 'foo bar' or 'Fred Brown' but not 'FreeBeer'.

### ConsecutiveCharactersMatcher

[](#consecutivecharactersmatcher)

Matches strings that include all the characters in the search relatively positioned within the string. It also calculates the percentage of characters in the string that are matched and applies the multiplier accordingly.

For Example, a search for 'fba' would match; 'Foo Bar' or 'Afraid of bats', but not 'fabulous'

### StartOfWordsMatcher

[](#startofwordsmatcher)

Matches the start of each word against each word in a search.

For example, a search for 'jo ta' would match; 'John Taylor' or 'Joshua B. Takeshi'

### StudlyCaseMatcher

[](#studlycasematcher)

Matches Studly Case strings using the first letters of the words only

For example a search for 'hp' would match; 'HtmlServiceProvider' or 'HashParser' but not 'hasProvider'

### InStringMatcher

[](#instringmatcher)

Matches against any occurrences of a string within a string and is case-insensitive.

For example, a search for 'smi' would match; 'John Smith' or 'Smiley Face'

### TimesInStringMatcher

[](#timesinstringmatcher)

Matches a string based on how many times the search string appears inside the string it then applies the multiplier for each occurrence. For example, a search for 'tha' would match; 'I hope that that cat has caught that mouse' (3 x multiplier) or 'Thanks, it was great!' (1 x multiplier)

### LevenshteinMatcher

[](#levenshteinmatcher)

See *Levenshtein Driver*

Extending
---------

[](#extending)

### Drivers

[](#drivers-1)

It's really easy to roll your own search drivers. Simply create a class that extends `TomLingham\Searchy\SearchDrivers\BaseSearchDriver` and add a property called `$matchers` with an array of matcher classes as the key and the multiplier for each matcher as the values. You can pick from the classes that are already included with Searchy or you can create your own.

### Matchers

[](#matchers-1)

To create your own matchers, you can create your own class that extends `TomLingham\Searchy\Matchers\BaseMatcher` and (for simple Matchers) override the `formatQuery` method to return a string formatted with `%` wildcards in required locations. For more advanced extensions you may need to override the `buildQuery` method and others as well.

Contributing &amp; Reporting Bugs
---------------------------------

[](#contributing--reporting-bugs)

If you would like to improve on the code that is here, feel free to submit a pull request.

If you find any bugs, submit them here and I will respond as soon as possible. Please make sure to include as much information as possible.

###  Health Score

36

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 75% 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 ~122 days

Recently: every ~356 days

Total

21

Last Release

1496d ago

Major Versions

1.0.0 → 2.0.02015-08-16

2.0.14 → 3.0.0-beta12017-04-27

2.0.16 → 3.0.0-beta22017-04-30

PHP version history (5 changes)1.0.0PHP &gt;=5.4.0

2.0.2PHP &gt;=5.5.0

2.0.11PHP ^5.5.9 || ^7.0

3.0.0-beta1PHP ^5.5.9 || &gt;=7.0

2.0.21PHP ^5.5.9 || ^7.0 || ^8.0

### Community

Maintainers

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

---

Top Contributors

[![TomLingham](https://avatars.githubusercontent.com/u/4160665?v=4)](https://github.com/TomLingham "TomLingham (84 commits)")[![vinkla](https://avatars.githubusercontent.com/u/499192?v=4)](https://github.com/vinkla "vinkla (11 commits)")[![jbrooksuk](https://avatars.githubusercontent.com/u/246103?v=4)](https://github.com/jbrooksuk "jbrooksuk (8 commits)")[![tantee](https://avatars.githubusercontent.com/u/24253163?v=4)](https://github.com/tantee "tantee (3 commits)")[![S3D-Jake](https://avatars.githubusercontent.com/u/12697178?v=4)](https://github.com/S3D-Jake "S3D-Jake (2 commits)")[![f-liva](https://avatars.githubusercontent.com/u/346224?v=4)](https://github.com/f-liva "f-liva (1 commits)")[![dciancu](https://avatars.githubusercontent.com/u/7402536?v=4)](https://github.com/dciancu "dciancu (1 commits)")[![esquinas](https://avatars.githubusercontent.com/u/9311114?v=4)](https://github.com/esquinas "esquinas (1 commits)")[![edwardsteven](https://avatars.githubusercontent.com/u/580129?v=4)](https://github.com/edwardsteven "edwardsteven (1 commits)")

---

Tags

searchlaravelfuzzy

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tantee-laravel-searchy-fork/health.svg)

```
[![Health](https://phpackages.com/badges/tantee-laravel-searchy-fork/health.svg)](https://phpackages.com/packages/tantee-laravel-searchy-fork)
```

###  Alternatives

[rap2hpoutre/similar-text-finder

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

14377.7k](/packages/rap2hpoutre-similar-text-finder)[remoblaser/search

A simple to implement Search for your Application

101.5k](/packages/remoblaser-search)

PHPackages © 2026

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