PHP Classes

File: src/Core/format.php

Recommend this page to a friend!
  Classes of AccountKiller   Fuse   src/Core/format.php   Download  
File: src/Core/format.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Fuse
Fuzzy search of arrays using the Bitap algorithm
Author: By
Last change:
Date: 1 year ago
Size: 899 bytes
 

Contents

Class file image Download
<?php

namespace Fuse\Core;

use function
Fuse\Core\config;

function
format(array $results, array $docs, array $options = []): array
{
   
$includeMatches = $options['includeMatches'] ?? config('includeMatches');
   
$includeScore = $options['includeScore'] ?? config('includeScore');

   
$transformers = [];

    if (
$includeMatches) {
       
$transformers[] = '\Fuse\Transform\transformMatches';
    }
    if (
$includeScore) {
       
$transformers[] = '\Fuse\Transform\transformScore';
    }

    return
array_map(function (array $result) use ($docs, $transformers) {
       
$data = [
           
'item' => $docs[$result['idx']],
           
'refIndex' => $result['idx'],
        ];

        if (
sizeof($transformers) > 0) {
            foreach (
$transformers as $transformer) {
               
$transformer($result, $data);
            }
        }

        return
$data;
    },
$results);
}