Skip to content

Commit

Permalink
Reverse sorted the docScores with asb value
Browse files Browse the repository at this point in the history
  • Loading branch information
aletail committed May 16, 2024
1 parent 4da10b2 commit c99618b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/SearchControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,26 @@ public function getSearchResults(string $search)
$classlist[ClassInfo::shortName($value)] = $value;
}

foreach ($res['ids'] as $result) {
if ($result) {
$parts = explode("_", $result);
if (isset($res["docScores"])) {
$docScores = $res['docScores'];
uasort($docScores, function ($a, $b) {
return abs($a) < abs($b) ? 1 : -1;
});
foreach ($docScores as $id => $score) {
$parts = explode("_", $id);
if ($obj = $classlist[$parts[0]]::get()->byID($parts[1])) {
$results->push($obj);
}
}
} else {
foreach ($res['ids'] as $result) {
if ($result) {
$parts = explode("_", $result);
if ($obj = $classlist[$parts[0]]::get()->byID($parts[1])) {
$results->push($obj);
}
}
}
}

$results->removeDuplicates('getSearchableID');
Expand Down

0 comments on commit c99618b

Please sign in to comment.