Skip to content

Commit

Permalink
Merge branch 'main' into feature/support-wheres
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell authored Jan 27, 2025
2 parents aefd744 + a9b4917 commit 39f8564
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

## v1.4.1 - 2024-11-14

### What's Changed

* Fix whereStatus error by @ryanmitchell in https://github.com/statamic-rad-pack/typesense/pull/9

**Full Changelog**: https://github.com/statamic-rad-pack/typesense/compare/v1.4.0...v1.4.1

## v1.4.0 - 2024-11-12

### What's Changed
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ Any additional settings you want to define per index can be included in the `sta
*/
'sort_by' => '_text_match(buckets: 10):desc,weighted_score:desc',
],

/*
Set this to true to maintain the sort score order that Typesense returns
*/
'maintain_rankings' => false,
],
],
```
6 changes: 4 additions & 2 deletions src/Typesense/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ public function searchUsingApi($query, array $options = []): array

$searchResults = $this->getOrCreateIndex()->documents->search($options);

$total = count($searchResults['hits']);

return [
'raw' => $searchResults,
'results' => collect($searchResults['hits'] ?? [])
->map(function ($result, $i) {
->map(function ($result, $i) use ($total) {
$result['document']['reference'] = $result['document']['id'];
$result['document']['search_score'] = (int) ($result['text_match'] ?? 0);
$result['document']['search_score'] = Arr::get($this->config, 'settings.maintain_ranking', false) ? ($total - $i) : (int) ($result['text_match'] ?? 0);

return $result['document'];
}),
Expand Down

0 comments on commit 39f8564

Please sign in to comment.