Skip to content
New issue

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

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

Already on GitHub? # to your account

ISSUE-171: Sorry, Forgot to remove the 'Desc' from the label when sorting #173

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Controller/AuthAutocompleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ public function handleAutocomplete(Request $request, $auth_type, $vocab = 'subje
}
}
// DO not cache NULL or FALSE. Those will be 401/403/500;
if ($results && is_array($results)) {
if ($results && is_array($results) && $input) {
// Cut the results to the desired number
// Easier than dealing with EACH API's custom return options
// Sort by levenstein
usort($results, fn($a, $b) => levenshtein($input, $a['label'] ?? '') <=> levenshtein($input, $b['label'] ?? ''));
// Sort by levenstein. I need to substract the 'desc' if present. Sorry Allison...
usort($results, fn($a, $b) => levenshtein($input, substr($a['label'] ?? '',0,strlen($a['desc'] ?? '') * (-1) )) <=> levenshtein($input, substr($b['label'] ?? '',0,strlen($b['desc'] ?? '')* (-1) )));
if (count($results) > $count) {
$results = array_slice($results, 0, $count);
}
Expand Down