Skip to content

Commit

Permalink
Make use of ranking score from Meilisearch
Browse files Browse the repository at this point in the history
  • Loading branch information
robbanl committed Oct 31, 2023
1 parent 644e81a commit 9a1a679
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Meilisearch/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,20 @@ public function update()
return $this;
}

public function searchUsingApi($query, $options = ['hitsPerPage' => 1000000])
public function searchUsingApi($query, $options = ['hitsPerPage' => 1000000, 'showRankingScore' => true])
{
try {
$searchResults = $this->getIndex()->search($query, $options);
} catch (\Exception $e) {
$this->handlemeilisearchException($e, 'searchUsingApi');
}

return collect($searchResults->getHits());
collect($searchResults->getHits())->map(function ($hit) {
$hit['search_score'] = (int) ceil($hit['_rankingScore'] * 1000);
unset($hit['_rankingScore']);

return $hit;
});
}

private function getIndex()
Expand Down

0 comments on commit 9a1a679

Please sign in to comment.