A Simple Fuzzy Search component using Levenshtein Distance (LD) Algorithm and Longest Common Substring (LCS) Algorithm.
- PHP >= 5.4
You can install and manage SimpleFuzzySearch by using Composer
composer require wataridori/simple-fuzzy-search
Or add wataridori/simple-fuzzy-search
into the require section of your composer.json
file then run composer update
$arrayData = [
[
'nickname' => 'thangtd90',
'fullname' => 'Tran Duc Thang',
],
[
'nickname' => 'trongbs',
'fullname' => 'Tran Ba Trong',
],
[
'nickname' => 'vigov5',
'fullname' => 'Nguyen Anh Tien',
],
[
'nickname' => 'kienBG',
'fullname' => 'Do Trung Kien',
],
[
'nickname' => 'vuong',
'fullname' => 'Nguyen Van Vuong',
],
[
'nickname' => 'dainghia',
'fullname' => 'Le Van Nghia',
],
[
'nickname' => 'tungctf',
'fullname' => 'Nguyen Duc Tung',
],
];
// Find by both nickname and fullname
$sfs = new SimpleFuzzySearch($this->arrayData, ['nickname', 'fullname'], 'tung');
// This will return "Nguyen Duc Tung" and "Do Trung Kien"
$results = $sfs->search();
// This will return "Tran Duc Thang"
$results = $sfs->search('trn dc thsng');
Just run phpunit
to start test.