PHP Classes

File: src/Core/computeScore.php

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

Contents

Class file image Download
<?php

namespace Fuse\Core;

use function
Fuse\Core\config;

// Practical scoring function
function computeScore(&$results, $options = []): void
{
   
$ignoreFieldNorm = $options['ignoreFieldNorm'] ?? config('ignoreFieldNorm');

    foreach (
$results as &$result) {
       
$totalScore = 1;

        foreach (
$result['matches'] as $match) {
           
$weight = $match['key']['weight'] ?? null;

           
$totalScore *= pow(
               
$match['score'] === 0 && $weight ? PHP_FLOAT_EPSILON : $match['score'],
                (
$weight ?: 1) * ($ignoreFieldNorm ? 1 : $match['norm']),
            );
        }

       
$result['score'] = $totalScore;
    }
}