1: <?php
2:
3: namespace vierbergenlars\Forage\ODM;
4:
5: use vierbergenlars\Forage\SearchQuery\Query;
6: use vierbergenlars\Forage\Transport\TransportInterface;
7:
8: /**
9: * A search query that automatically converts all search results to an hydrated object
10: */
11: class SearchQuery extends Query
12: {
13:
14: protected $searchResultClass = '\vierbergenlars\Forage\ODM\SearchResult';
15:
16: /**
17: * Settings for object hydration
18: * @var \vierbergenlars\Forage\ODM\HydrationSettingsInterface
19: */
20: protected $hydrationSettings;
21:
22: /**
23: * Creates a new search query
24: *
25: * @internal
26: * @param \vierbergenlars\Forage\Transport\TransportInterface $transport
27: * @param \vierbergenlars\Forage\ODM\HydrationSettingsInterface $hydrationSettings
28: * @param string $query
29: */
30: public function __construct(TransportInterface $transport,
31: HydrationSettingsInterface $hydrationSettings,
32: $query = '')
33: {
34: $this->hydrationSettings = $hydrationSettings;
35: parent::__construct($transport, $query);
36: }
37:
38: /**
39: * Executes the search and hydrates the result
40: *
41: * @return \vierbergenlars\Forage\ODM\SearchResult
42: */
43: public function execute() {
44: $searchResult = parent::execute();
45: $searchResult->hydrate($this->hydrationSettings);
46: return $searchResult;
47: }
48: }
49: