PHP Classes

File: tests/FuzzySearch/SortedSearchResultsTest.php

Recommend this page to a friend!
  Classes of AccountKiller   Fuse   tests/FuzzySearch/SortedSearchResultsTest.php   Download  
File: tests/FuzzySearch/SortedSearchResultsTest.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: 1 month ago
Size: 1,229 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

use
Fuse\Fuse;

beforeEach(function () {
   
$this->fuse = new Fuse(
        [
            [
               
'title' => 'Right Ho Jeeves',
               
'author' => [
                   
'firstName' => 'P.D',
                   
'lastName' => 'Woodhouse',
                ],
            ],
            [
               
'title' => 'The Code of the Wooster',
               
'author' => [
                   
'firstName' => 'P.D',
                   
'lastName' => 'Woodhouse',
                ],
            ],
            [
               
'title' => 'Thank You Jeeves',
               
'author' => [
                   
'firstName' => 'P.D',
                   
'lastName' => 'Woodhouse',
                ],
            ],
        ],
        [
           
'keys' => ['title', 'author.firstName', 'author.lastName'],
        ],
    );
});

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

   
// We get the properly ordered results
   
expect($result[0]['item']['title'])->toBe('The Code of the Wooster');
   
expect($result[1]['item']['title'])->toBe('Right Ho Jeeves');
   
expect($result[2]['item']['title'])->toBe('Thank You Jeeves');
});