File: src/Bitap/score.php

Recommend this page to a friend!
  Classes of AccountKiller  >  Fuse  >  src/Bitap/score.php  >  Download  
File: src/Bitap/score.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: Comply with PSR-2
Date: 2 years ago
Size: 560 bytes
 

Contents

Class file image Download
<?php namespace Fuse\Bitap;

function
score($pattern, $options = [])
{
   
$options = array_merge([
       
'errors' => 0,
       
'currentLocation' => 0,
       
'expectedLocation' => 0,
       
'distance' => 100
   
], $options);

   
$accuracy = $options['errors'] / mb_strlen($pattern);
   
$proximity = abs($options['expectedLocation'] - $options['currentLocation']);

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

    return
$accuracy + ($proximity / $options['distance']);
}


For more information send a message to info at phpclasses dot org.