Untitled

mail@pastecode.io avatar
unknown
php
a month ago
962 B
4
Indexable
Never
<?php

include __DIR__ .'/vendor/autoload.php';

$db = new Pdo('mysql:host=db;dbname=test', 'root', 'root');

$data = $db->query('SELECT * FROM data');



$input = [
    'Endrőd',
    'Béláné',
    'Budapest'
];

$i = 0;

use FuzzyWuzzy\Fuzz;
use FuzzyWuzzy\Process;

$fuzz = new Fuzz();

$results = [

];

$start = microtime(true);

while ($row = $data->fetch(PDO::FETCH_NUM)) {

    $text = implode(' ', [
        $row[1],$row[2], $row[3]
    ]);


    $ratio = $fuzz->ratio($text, implode(' ', $input));

    if ($ratio > 85) {
        $results[] = [
            'ratio' => $ratio,
            'found' => $text
        ];
    }

    if ($i % 10000 === 0) {
        echo $i . " checked\n";
    }

    $i++;
}

$end = number_format(microtime(true) - $start, 4);

echo "\n\nSearched: " . implode(' ', $input) . "\n";
echo "Run time: " . $end . "\n";

foreach ($results as $result) {
    echo "\t ratio:" . $result['ratio'] . "\t" . $result['found'] . "\n";
}
Leave a Comment