Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Taglist.php #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Update Taglist.php #46

wants to merge 1 commit into from

Conversation

neomorina
Copy link
Contributor

This sorting algorithm helps on showing the most similar labels at the first row.

This sorting algorithm helps on showing the most similar labels at the first row.
@neomorina
Copy link
Contributor Author

neomorina commented Sep 4, 2018

For much better results i actually recommend implementing this third party library through Composer https://github.com/wyndow/fuzzywuzzy
The code would look like this.

use FuzzyWuzzy\Fuzz;      
$fuzz = new Fuzz();

usort($results, function ($a, $b) use ($query, $fuzz) {
   $a_label = is_array($a['label']) ? $a['label']['label'] : $a['label'];
   $b_label = is_array($b['label']) ? $b['label']['label'] : $b['label'];

   $percent_a = $fuzz->tokenSetRatio($query, $a_label);
   $percent_b = $fuzz->tokenSetRatio($query, $b_label);

   return $percent_a === $percent_b ? 0 : ($percent_a > $percent_b ? -1 : 1);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant