Skip to content

Commit

Permalink
Merge pull request #2 from arminwinkt/revert-1-fix/typesenses-missing…
Browse files Browse the repository at this point in the history
…-metadata

Revert "fix: missing scout metadata for typesense search"
  • Loading branch information
arminwinkt authored Sep 24, 2024
2 parents acb57e3 + 27191c8 commit e3283cb
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 53 deletions.
13 changes: 0 additions & 13 deletions src/Engines/TypesenseEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,19 +392,6 @@ 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()]] ?? [];

foreach ($result as $key => $value) {
if ($key === 'document') {
continue;
}

$model->withScoutMetadata($key, $value);
}

return $model;
})
->sortBy(static function ($model) use ($objectIdPositions) {
return $objectIdPositions[$model->getScoutKey()];
})
Expand Down
40 changes: 0 additions & 40 deletions tests/Unit/TypesenseEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,46 +183,6 @@ public function test_map_ids_method(): void
$this->assertEquals([1, 2, 3], $mappedIds->toArray());
}

public function test_map_correctly_maps_results_to_models()
{
$engine = new TypesenseEngine($this->createMock(TypesenseClient::class));

$model = m::mock(stdClass::class);
$model->shouldReceive(['getScoutKeyName' => 'id']);
$model->shouldReceive('getScoutModelsByIds')->andReturn(Collection::make([
new SearchableModel([
'document' => [
[
'id' => 1,
'name' => 'test',
]
],
'geo_distance_meters' => ['location' => 5],
'highlights' => [],
]),
]));

$builder = m::mock(Builder::class);

$results = $engine->map($builder, [
'found' => 1,
'hits' => [
[
'document' => ['id' => 1, 'name' => 'test'],
'geo_distance_meters' => ['location' => 5],
'highlights' => [],
],
],
], $model);

$this->assertCount(1, $results);
$this->assertEquals(['id' => 1, 'name' => 'test'], $results->first()->toArray());
$this->assertEquals(
['geo_distance_meters' => ['location' => 5], 'highlights' => []],
$results->first()->scoutMetadata()
);
}

public function test_get_total_count_method(): void
{
// Sample search results with 'found' key
Expand Down

0 comments on commit e3283cb

Please sign in to comment.