-
Notifications
You must be signed in to change notification settings - Fork 330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: typesense missing scoutmetadata #868
base: 10.x
Are you sure you want to change the base?
Fix: typesense missing scoutmetadata #868
Conversation
fix: missing scout metadata for typesense search
…-metadata Revert "fix: missing scout metadata for typesense search"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some notes on testing to cover all edge cases, otherwise looks good!
$result = $hits[$objectIdPositions[$model->getScoutKey()]] ?? []; | ||
|
||
foreach ($result as $key => $value) { | ||
if ($key === 'document') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test for this case specifically?
@@ -392,6 +392,19 @@ public function map(Builder $builder, $results, $model) | |||
->filter(static function ($model) use ($objectIds) { | |||
return in_array($model->getScoutKey(), $objectIds, false); | |||
}) | |||
->map(static function ($model) use ($hits, $objectIdPositions) { | |||
$result = $hits[$objectIdPositions[$model->getScoutKey()]] ?? []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a test for the fallback of the empty array
tests/Unit/TypesenseEngineTest.php
Outdated
$model->shouldReceive(['getScoutKeyName' => 'id']); | ||
$model->shouldReceive('getScoutModelsByIds')->andReturn( | ||
Collection::make([ | ||
new SearchableModel([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add some more response data to verify handling of multiple results?
Drafting pending response to feedback. |
Thank you @tharropoulos for your feedback. |
All looks well, but could you lastly add some integration tests as well? As we are mocking the Typesense Client itself, we could miss some details in the process. Otherwise, this covers every branch inside the function. |
This Pull Request fixes the missing
scoutMetadata
for typesense search results.As written in the Typesense documentation, there are additional data that gets returned by typesense.
For example
highlights
, which shows what to highlight in your search results.For me specifically the
geo_distance_meters
value was very intresting if you query for a geo search:This PR adds all this additional data to the model via scouts
scoutMetadata