1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* YAWIK |
4
|
|
|
* |
5
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
6
|
|
|
* @license MIT |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Solr\Paginator\Adapter; |
10
|
|
|
|
11
|
|
|
use Solr\Exception\ServerException; |
12
|
|
|
use Solr\Filter\AbstractPaginationQuery; |
13
|
|
|
use Zend\Paginator\Adapter\AdapterInterface; |
14
|
|
|
use Zend\Stdlib\Parameters; |
15
|
|
|
use Solr\Bridge\ResultConverter; |
16
|
|
|
|
17
|
|
|
class SolrAdapter implements AdapterInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var \SolrClient |
21
|
|
|
*/ |
22
|
|
|
protected $client; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var Parameters |
26
|
|
|
*/ |
27
|
|
|
protected $params; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var int |
31
|
|
|
*/ |
32
|
|
|
protected $count; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var \SolrQuery |
36
|
|
|
*/ |
37
|
|
|
protected $query; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Store current query response from solr server |
41
|
|
|
* |
42
|
|
|
* @var \SolrQueryResponse |
43
|
|
|
*/ |
44
|
|
|
protected $response; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var AbstractPaginationQuery |
48
|
|
|
*/ |
49
|
|
|
protected $filter; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var ResultConverter |
53
|
|
|
*/ |
54
|
|
|
protected $resultConverter; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* SolrAdapter constructor. |
58
|
|
|
* |
59
|
|
|
* @param \SolrClient $client |
60
|
|
|
* @param AbstractPaginationQuery $filter |
61
|
|
|
* @param ResultConverter $resultConverter |
62
|
|
|
* @param array $params |
63
|
|
|
*/ |
64
|
|
|
public function __construct($client,$filter,$resultConverter,$params=array()) |
65
|
|
|
{ |
66
|
|
|
$this->client = $client; |
67
|
|
|
$this->filter = $filter; |
68
|
|
|
$this->resultConverter = $resultConverter; |
69
|
|
|
$this->params = $params; |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @inheritdoc |
74
|
|
|
*/ |
75
|
|
|
public function getItems($offset, $itemCountPerPage) |
76
|
|
|
{ |
77
|
|
|
return $this->resultConverter->convert( |
78
|
|
|
$this->filter, |
79
|
|
|
$this->getResponse($offset,$itemCountPerPage) |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @inheritdoc |
85
|
|
|
* @return mixed |
86
|
|
|
* @throws \Exception |
87
|
|
|
*/ |
88
|
|
|
public function count() |
89
|
|
|
{ |
90
|
|
|
$response = $this->getResponse()->getArrayResponse(); |
91
|
|
|
return $response['response']['numFound']; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Process query into server |
96
|
|
|
* |
97
|
|
|
* @param int $offset |
98
|
|
|
* @param int $itemCountPerPage |
99
|
|
|
* @return \SolrQueryResponse |
100
|
|
|
* @throws \Exception |
101
|
|
|
*/ |
102
|
|
|
protected function getResponse($offset=0,$itemCountPerPage=5) |
103
|
|
|
{ |
104
|
|
|
if(!is_object($this->response)){ |
105
|
|
|
$query = new \SolrQuery(); |
106
|
|
|
$query = $this->filter->filter($this->params,$query); |
|
|
|
|
107
|
|
|
$query->setStart($offset); |
108
|
|
|
$query->setRows($itemCountPerPage); |
109
|
|
|
try{ |
110
|
|
|
$this->response = $this->client->query($query); |
111
|
|
|
}catch (\Exception $e){ |
112
|
|
|
$message = 'Failed to process query'; |
113
|
|
|
throw new ServerException($message,$e->getCode(),$e); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
return $this->response; |
117
|
|
|
} |
118
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..