wataridori/simple-fuzzy-search

Simple Fuzzy Search for PHP

0.1.1 2016-03-12 13:38 UTC

This package is auto-updated.

Last update: 2024-10-15 20:31:25 UTC


README

StyleCI Build Status Latest Stable Version Total Downloads Latest Unstable Version License

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.