-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathResultSearch.php
More file actions
101 lines (80 loc) · 2.18 KB
/
ResultSearch.php
File metadata and controls
101 lines (80 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php declare(strict_types = 1);
namespace Spameri\ElasticQuery\Response;
/**
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-search-API.html
*/
class ResultSearch implements ResultInterface
{
/**
* @var \Spameri\ElasticQuery\Response\Stats
*/
private $stats;
/**
* @var \Spameri\ElasticQuery\Response\Shards
*/
private $shards;
/**
* @var \Spameri\ElasticQuery\Response\Result\HitCollection
*/
private $hitCollection;
/**
* @var \Spameri\ElasticQuery\Response\Result\AggregationCollection
*/
private $aggregationCollection;
public function __construct(
Stats $stats
, Shards $shards
, \Spameri\ElasticQuery\Response\Result\HitCollection $hitCollection
, \Spameri\ElasticQuery\Response\Result\AggregationCollection $aggregationCollection
)
{
$this->stats = $stats;
$this->shards = $shards;
$this->hitCollection = $hitCollection;
$this->aggregationCollection = $aggregationCollection;
}
public function stats(): \Spameri\ElasticQuery\Response\Stats
{
return $this->stats;
}
public function shards(): \Spameri\ElasticQuery\Response\Shards
{
return $this->shards;
}
public function hits(): \Spameri\ElasticQuery\Response\Result\HitCollection
{
return $this->hitCollection;
}
public function aggregations(): \Spameri\ElasticQuery\Response\Result\AggregationCollection
{
return $this->aggregationCollection;
}
public function getHit(
string $id
): \Spameri\ElasticQuery\Response\Result\Hit
{
/** @var \Spameri\ElasticQuery\Response\Result\Hit $hit */
foreach ($this->hitCollection as $hit) {
if ($hit->id() === $id) {
return $hit;
}
}
throw new \Spameri\ElasticQuery\Exception\HitNotFound(
'Hit with id: ' . $id . 'not found.'
);
}
public function getAggregation(
string $name
): \Spameri\ElasticQuery\Response\Result\Aggregation
{
/** @var \Spameri\ElasticQuery\Response\Result\Aggregation $aggregation */
foreach ($this->aggregationCollection as $aggregation) {
if ($aggregation->name() === $name) {
return $aggregation;
}
}
throw new \Spameri\ElasticQuery\Exception\AggregationNotFound(
'Aggregation with name: ' . $name . ' has not been found.'
);
}
}