14
14
15
15
namespace Elastic \Elasticsearch \Helper \Iterators ;
16
16
17
+ use Countable ;
18
+ use Elastic \Elasticsearch \Exception \ClientResponseException ;
19
+ use Elastic \Elasticsearch \Exception \ServerResponseException ;
17
20
use Iterator ;
18
21
19
- class SearchHitIterator implements Iterator, \ Countable
22
+ class SearchHitIterator implements Iterator, Countable
20
23
{
21
24
22
25
/**
@@ -58,6 +61,8 @@ public function __construct(SearchResponseIterator $searchResponses)
58
61
* Rewinds the internal SearchResponseIterator and itself
59
62
*
60
63
* @return void
64
+ * @throws ClientResponseException
65
+ * @throws ServerResponseException
61
66
* @see Iterator::rewind()
62
67
*/
63
68
public function rewind (): void
@@ -66,14 +71,14 @@ public function rewind(): void
66
71
$ this ->searchResponses ->rewind ();
67
72
68
73
// The first page may be empty. In that case, the next page is fetched.
69
- $ current_page = $ this ->searchResponses ->current ();
70
- if ($ this ->searchResponses ->valid () && empty ($ current_page ['hits ' ]['hits ' ])) {
74
+ $ currentPage = $ this ->searchResponses ->current ();
75
+ if ($ this ->searchResponses ->valid () && empty ($ currentPage ['hits ' ]['hits ' ])) {
71
76
$ this ->searchResponses ->next ();
72
77
}
73
78
74
79
$ this ->count = 0 ;
75
- if (isset ($ current_page ['hits ' ]) && isset ( $ current_page ['hits ' ]['total ' ])) {
76
- $ this ->count = $ current_page ['hits ' ]['total ' ]['value ' ] ?? $ current_page ['hits ' ]['total ' ];
80
+ if (isset ($ currentPage ['hits ' ][ ' total ' ][ ' value ' ], $ currentPage ['hits ' ]['total ' ])) {
81
+ $ this ->count = $ currentPage ['hits ' ]['total ' ]['value ' ] ?? $ currentPage ['hits ' ]['total ' ];
77
82
}
78
83
79
84
$ this ->readPageData ();
@@ -85,15 +90,17 @@ public function rewind(): void
85
90
* pointer to the first hit in the page.
86
91
*
87
92
* @return void
93
+ * @throws ClientResponseException
94
+ * @throws ServerResponseException
88
95
* @see Iterator::next()
89
96
*/
90
97
public function next (): void
91
98
{
92
99
$ this ->currentKey ++;
93
100
$ this ->currentHitIndex ++;
94
- $ current_page = $ this ->searchResponses ->current ();
95
- if (isset ($ current_page ['hits ' ]['hits ' ][$ this ->currentHitIndex ])) {
96
- $ this ->currentHitData = $ current_page ['hits ' ]['hits ' ][$ this ->currentHitIndex ];
101
+ $ currentPage = $ this ->searchResponses ->current ();
102
+ if (isset ($ currentPage ['hits ' ]['hits ' ][$ this ->currentHitIndex ])) {
103
+ $ this ->currentHitData = $ currentPage ['hits ' ]['hits ' ][$ this ->currentHitIndex ];
97
104
} else {
98
105
$ this ->searchResponses ->next ();
99
106
$ this ->readPageData ();
@@ -141,9 +148,9 @@ public function key(): int
141
148
private function readPageData (): void
142
149
{
143
150
if ($ this ->searchResponses ->valid ()) {
144
- $ current_page = $ this ->searchResponses ->current ();
151
+ $ currentPage = $ this ->searchResponses ->current ();
145
152
$ this ->currentHitIndex = 0 ;
146
- $ this ->currentHitData = $ current_page ['hits ' ]['hits ' ][$ this ->currentHitIndex ];
153
+ $ this ->currentHitData = $ currentPage ['hits ' ]['hits ' ][$ this ->currentHitIndex ];
147
154
} else {
148
155
$ this ->currentHitData = null ;
149
156
}
0 commit comments