1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Manticoresearch; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Manticore result set |
8
|
|
|
* List hits returned by a search |
9
|
|
|
* Implements iterator and countable |
10
|
|
|
* @category ManticoreSearch |
11
|
|
|
* @package ManticoreSearch |
12
|
|
|
* @author Adrian Nuta <[email protected]> |
13
|
|
|
* @link https://manticoresearch.com |
14
|
|
|
* @see \Iterator |
15
|
|
|
*/ |
16
|
|
|
class ResultSet implements \Iterator, \Countable |
17
|
|
|
{ |
18
|
|
|
private $_position = 0; |
19
|
|
|
private $_response; |
20
|
|
|
private $_array = []; |
21
|
|
|
private $_total = 0; |
22
|
|
|
private $_took; |
23
|
|
|
private $_timed_out; |
24
|
|
|
private $_profile; |
25
|
|
|
|
26
|
|
|
public function __construct($responseObj) |
27
|
|
|
{ |
28
|
|
|
$this->_response = $responseObj; |
29
|
|
|
$response = $responseObj->getResponse(); |
30
|
|
|
if (isset($response['hits']['hits'])) { |
31
|
|
|
$this->_array = $response['hits']['hits']; |
32
|
|
|
$this->_total = $response['hits']['total']; |
33
|
|
|
} else { |
34
|
|
|
$this->_total = 0; |
35
|
|
|
} |
36
|
|
|
$this->_took = $response['took']; |
37
|
|
|
$this->_timed_out = $response['timed_out']; |
38
|
|
|
if (isset($response['profile'])) { |
39
|
|
|
$this->_profile = $response['profile']; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function rewind() |
45
|
|
|
{ |
46
|
|
|
$this->_position = 0; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function current() |
50
|
|
|
{ |
51
|
|
|
return new ResultHit($this->_array[$this->_position]); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function next() |
55
|
|
|
{ |
56
|
|
|
$this->_position++; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function valid() |
60
|
|
|
{ |
61
|
|
|
return isset($this->_array[$this->_position]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function key() |
65
|
|
|
{ |
66
|
|
|
return $this->_position; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getTotal() |
70
|
|
|
{ |
71
|
|
|
return $this->_total; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getTime() |
75
|
|
|
{ |
76
|
|
|
return $this->_took; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function hasTimedout() |
80
|
|
|
{ |
81
|
|
|
return $this->_timed_out; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getResponse() |
85
|
|
|
{ |
86
|
|
|
return $this->_response; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function count() |
90
|
|
|
{ |
91
|
|
|
return count($this->_array); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function getProfile() |
95
|
|
|
{ |
96
|
|
|
return $this->_profile; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |