PHP code example of tomtruyen / fuzzyness

1. Go to this page and download the library: Download tomtruyen/fuzzyness library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tomtruyen / fuzzyness example snippets


DB::table('users')
  ->whereFuzzy('name', 'jd', false) // matches John Doe
  ->first();

User::whereFuzzy('name', 'jd', false) // matches John Doe
    ->first();

User::whereFuzzy('name', 'jd', false)  // matches John Doe
    ->whereFuzzy('email', 'gm', false) // matches @gmail.com
    ->first();

DB::table('users')
  ->whereCustomFuzzy('name', 'jd', [StartOfWordsMatcher::class => 35]) // matches John Doe
  ->first();

User::whereCustomFuzzy('name', 'jd', [StartOfWordsMatcher::class => 35]) // matches John Doe
    ->first();

array $matchers = [
    ExactMatcher::class                 => 100,
    StartOfStringMatcher::class         => 50,
    AcronymMatcher::class               => 42,
    ConsecutiveCharactersMatcher::class => 40,
    StartOfWordsMatcher::class          => 35,
    StudlyCaseMatcher::class            => 32,
    InStringMatcher::class              => 30,
    TimesInStringMatcher::class         => 8,
];

User::whereFuzzy('email', 'gm') // relevance_email

User::whereFuzzy('name', 'jd')
    ->orderByFuzzy('name')
    ->first();

// Equivalent to:

User::whereFuzzy('name', 'jd')
    ->orderBy('relevance_name', 'desc')
    ->first();

User::whereFuzzy('name', 'jd')
    ->whereFuzzy('email', 'gm')
    ->orderByFuzzy(['name', 'email'])
    ->first();

// Equivalent to:

User::whereFuzzy('name', 'jd')
    ->orderBy('relevance_name', 'desc')
    ->orderBy('relevance_email', 'desc')
    ->first();