PHP Classes

File: src/Search/Bitap/computeScore.php

Recommend this page to a friend!
  Classes of AccountKiller   Fuse   src/Search/Bitap/computeScore.php   Download  
File: src/Search/Bitap/computeScore.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: 756 bytes
 

Contents

Class file image Download
<?php

namespace Fuse\Search\Bitap;

use function
Fuse\Core\config;

function
computeScore(string $pattern, array $options = [])
{
   
$errors = $options['errors'] ?? 0;
   
$currentLocation = $options['currentLocation'] ?? 0;
   
$expectedLocation = $options['expectedLocation'] ?? 0;
   
$distance = $options['distance'] ?? config('distance');
   
$ignoreLocation = $options['ignoreLocation'] ?? config('ignoreLocation');

   
$accuracy = $errors / mb_strlen($pattern);

    if (
$ignoreLocation) {
        return
$accuracy;
    }

   
$proximity = abs($expectedLocation - $currentLocation);

    if (!
$distance) {
       
// Dodge divide by zero error.
       
return $proximity ? 1.0 : $accuracy;
    }

    return
$accuracy + $proximity / $distance;
}