Skip to content

Update Taglist.php#46

Open
neomorina wants to merge 1 commit into
EGroupware:masterfrom
neomorina:patch-4
Open

Update Taglist.php#46
neomorina wants to merge 1 commit into
EGroupware:masterfrom
neomorina:patch-4

Conversation

@neomorina

Copy link
Copy Markdown
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

neomorina commented Sep 4, 2018

Copy link
Copy Markdown
Contributor Author

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

Development

Successfully merging this pull request may close these issues.

1 participant