Skip to content

Commit

Permalink
fix(search): SearchResult::getRaw() introduced
Browse files Browse the repository at this point in the history
  • Loading branch information
Guikingone committed Nov 24, 2020
1 parent 9f8e368 commit 823beb5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
17 changes: 16 additions & 1 deletion src/Search/SearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use function array_filter;
use ArrayIterator;
use function count;
use Countable;
use IteratorAggregate;

Expand Down Expand Up @@ -57,6 +56,11 @@ class SearchResult implements Countable, IteratorAggregate
*/
private $facetsDistribution;

/**
* @var array<string, mixed>
*/
private $raw;

public function __construct(array $body)
{
$this->hits = $body['hits'] ?? [];
Expand All @@ -68,6 +72,7 @@ public function __construct(array $body)
$this->query = $body['query'];
$this->exhaustiveFacetsCount = $body['exhaustiveFacetsCount'] ?? null;
$this->facetsDistribution = $body['facetsDistribution'] ?? [];
$this->raw = $body;
}

/**
Expand Down Expand Up @@ -150,6 +155,16 @@ public function getFacetsDistribution(): array
return $this->facetsDistribution;
}

/**
* Return the original search result.
*
* @return array<string, mixed>
*/
public function getRaw(): array
{
return $this->raw;
}

public function toArray(): array
{
return [
Expand Down
12 changes: 6 additions & 6 deletions tests/Endpoints/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ public function testBasicSearchWithFacetFilters(): void
'facetFilters' => [['genre:fantasy']],
]);
$this->assertSame(1, $response->getMatches());
$this->assertArrayNotHasKey('facetsDistribution', $response->toArray());
$this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->toArray());
$this->assertArrayNotHasKey('facetsDistribution', $response->getRaw());
$this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->getRaw());
$this->assertSame(4, $response->getHit(0)['id']);
}

Expand All @@ -170,8 +170,8 @@ public function testBasicSearchWithMultipleFacetFilters(): void
'facetFilters' => ['genre:fantasy', ['genre:fantasy', 'genre:fantasy']],
]);
$this->assertSame(1, $response->getMatches());
$this->assertArrayNotHasKey('facetsDistribution', $response->toArray());
$this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->toArray());
$this->assertArrayNotHasKey('facetsDistribution', $response->getRaw());
$this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->getRaw());
$this->assertSame(4, $response->getHit(0)['id']);
}

Expand All @@ -185,8 +185,8 @@ public function testCustomSearchWithFacetFiltersAndAttributesToRetrieve(): void
'attributesToRetrieve' => ['id', 'title'],
]);
$this->assertSame(1, $response->getMatches());
$this->assertArrayNotHasKey('facetsDistribution', $response->toArray());
$this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->toArray());
$this->assertArrayNotHasKey('facetsDistribution', $response->getRaw());
$this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->getRaw());
$this->assertSame(4, $response->getHit(0)['id']);
$this->assertArrayHasKey('id', $response->getHit(0));
$this->assertArrayHasKey('title', $response->getHit(0));
Expand Down

0 comments on commit 823beb5

Please sign in to comment.