PHP Classes

File: tests/FuzzySearch/SearchLocationTest.php

Recommend this page to a friend!
  Classes of AccountKiller   Fuse   tests/FuzzySearch/SearchLocationTest.php   Download  
File: tests/FuzzySearch/SearchLocationTest.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Fuse
Fuzzy search of arrays using the Bitap algorithm
Author: By
Last change:
Date: 11 days ago
Size: 712 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

use
Fuse\Fuse;

beforeEach(function () {
   
$this->fuse = new Fuse(
        [
            [
               
'name' => 'Hello World',
            ],
        ],
        [
           
'keys' => ['name'],
           
'includeScore' => true,
           
'includeMatches' => true,
        ],
    );
});

test('when searching for the term Wor', function () {
   
$result = $this->fuse->search('wor');

   
// We get a list whose indices are found
   
expect($result[0]['matches'][0]['indices'][0])->toBe([4, 4]);
   
expect($result[0]['matches'][0]['indices'][1])->toBe([6, 8]);

   
// with original text values
   
expect($result[0]['matches'][0]['value'])->toBe('Hello World');
});