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