Skip to content

Commit

Permalink
Merge pull request #151 from apisearch-io/feature/added-set-subresults
Browse files Browse the repository at this point in the history
Addd setSubresults method in Result
  • Loading branch information
mmoreram authored Apr 13, 2023
2 parents d59c782 + 63cf67a commit 5bb7672
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Result/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,16 @@ public function getSubresults(): array
return $this->subresults;
}

/**
* @param array $subResults
*
* @return array
*/
public function setSubResults(array $subResults)
{
$this->subresults = $subResults;
}

/**
* Set metadata.
*
Expand Down
13 changes: 13 additions & 0 deletions Tests/Result/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,19 @@ public function testMultiResult()
$this->assertEquals(3, $subqueries['res1']->getTotalHits());
$this->assertEquals(4, $subqueries['res2']->getTotalHits());
$this->assertEquals(5, $subqueries['res3']->getTotalHits());

$result = Result::createFromArray([]);
$result->setSubResults([
'res1' => Result::create(Query::createMatchAll()->identifyWith('1'), 10, 3, null, [], []),
'res2' => Result::create(Query::createMatchAll()->identifyWith('2'), 10, 4, null, [], []),
'res3' => Result::create(Query::createMatchAll()->identifyWith('3'), 10, 5, null, [], []),
]);

$this->assertCount(3, $result->getSubresults());
$subqueries = HttpHelper::emulateHttpTransport($result)->getSubresults();
$this->assertEquals(3, $subqueries['res1']->getTotalHits());
$this->assertEquals(4, $subqueries['res2']->getTotalHits());
$this->assertEquals(5, $subqueries['res3']->getTotalHits());
}

/**
Expand Down

0 comments on commit 5bb7672

Please sign in to comment.