wataridori / simple-fuzzy-search
Simple Fuzzy Search for PHP
Installs: 57 392
Dependents: 0
Suggesters: 0
Security: 0
Stars: 26
Watchers: 3
Forks: 2
Open Issues: 2
This package is auto-updated.
Last update: 2024-10-15 20:31:25 UTC
README
About
A Simple Fuzzy Search component using Levenshtein Distance (LD) Algorithm and Longest Common Substring (LCS) Algorithm.
Requirement
- PHP >= 5.4
Install
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
Usage
$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');
Test
Just run phpunit
to start test.