Subversion Repositories cheapmusic

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
93 - 1
<?php namespace Fuse\Bitap;
2
 
3
function score($pattern, $options = [])
4
{
5
    $options = array_merge([
6
        'errors' => 0,
7
        'currentLocation' => 0,
8
        'expectedLocation' => 0,
9
        'distance' => 100
10
    ], $options);
11
 
12
    $accuracy = $options['errors'] / mb_strlen($pattern);
13
    $proximity = abs($options['expectedLocation'] - $options['currentLocation']);
14
 
15
    if (!$options['distance']) {
16
        // Dodge divide by zero error.
17
        return $proximity ? 1.0 : $accuracy;
18
    }
19
 
20
    return $accuracy + ($proximity / $options['distance']);
21
}