PHP Classes

File: tests/LogicalSearch/SearchWithDottedKeysTest.php

Recommend this page to a friend!
  Classes of AccountKiller   Fuse   tests/LogicalSearch/SearchWithDottedKeysTest.php   Download  
File: tests/LogicalSearch/SearchWithDottedKeysTest.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: 952 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

use
Fuse\Fuse;

beforeEach(function () {
   
$options = [
       
'useExtendedSearch' => true,
       
'includeScore' => true,
       
'keys' => ['title', ['author', 'first.name'], ['author', 'last.name'], 'author.age'],
    ];

   
$list = [
        [
           
'title' => 'Old Man\'s War',
           
'author' => [
               
'first.name' => 'John',
               
'last.name' => 'Scalzi',
               
'age' => '61',
            ],
        ],
    ];

   
$this->fuse = new Fuse($list, $options);
});

it('performs deep nested and/or search', function () {
   
$result = $this->fuse->search([
       
'$and' => [
            [
               
'$path' => ['author', 'first.name'],
               
'$val' => 'jon',
            ],
            [
               
'$path' => ['author', 'last.name'],
               
'$val' => 'scazi',
            ],
        ],
    ]);

   
expect($result)->toHaveCount(1);
});