public function testFilter() { $scopePersons = $this->getScopeMock(); $scopeLocations = $this->getScopeMock(); $arthur = $this->getResultMock($scopePersons); $cologne = $this->getResultMock($scopeLocations); $collection = new ResultCollection(); $collection->add($arthur)->add($cologne); $this->assertCount(2, $collection); $foundPersons = $collection->filter($scopePersons); $this->assertCount(1, $foundPersons); $this->assertContains($arthur, $foundPersons); $foundLocations = $collection->filter($scopeLocations); $this->assertCount(1, $foundLocations); $this->assertContains($cologne, $foundLocations); }
/** * Perform the search based on the query. * * The query may be anything, from a simple search string to a complex query structure. * It's based on a contract between the engine and the application. * * @param mixed $query * * @return ResultInterface[]|ResultCollection */ public function search($query) { $results = new ResultCollection(); foreach ($this->engines as $eachEngine) { if (!$eachEngine->supports($query)) { continue; } if ($more = $eachEngine->search($query)) { if (!is_array($more) and !$more instanceof \Traversable) { throw new DomainException('The returned result set is not traversable.'); } foreach ($more as $eachResult) { $results->add($eachResult); } } } return $results; }