|
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\Bridge; |
|
11
|
|
|
|
|
12
|
|
|
use Solr\Options\ModuleOptions; |
|
13
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
14
|
|
|
use SolrClient; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Manage connection with the SolrServer |
|
18
|
|
|
* |
|
19
|
|
|
* @author Anthonius Munthi <[email protected]> |
|
20
|
|
|
* @author Miroslav Fedeleš <[email protected]> |
|
21
|
|
|
* @since 0.26 |
|
22
|
|
|
* @package Solr\Bridge |
|
23
|
|
|
*/ |
|
24
|
|
|
class Manager |
|
25
|
|
|
{ |
|
26
|
|
|
const SOLR_DATE_FORMAT = 'Y-m-d\TH:i:s\Z'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var ModuleOptions |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $options; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var array |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $clients = []; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Manager constructor. |
|
40
|
|
|
* @param ModuleOptions $options |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct(ModuleOptions $options) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->options = $options; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Get SolrClient with custom path option |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $path |
|
51
|
|
|
* @return SolrClient |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getClient($path = '/solr') |
|
54
|
|
|
{ |
|
55
|
|
|
$options = $this->options; |
|
56
|
|
|
$options = [ |
|
57
|
|
|
'secure' => $options->isSecure(), |
|
58
|
|
|
'hostname' => $options->getHostname(), |
|
59
|
|
|
'port' => $options->getPort(), |
|
60
|
|
|
'path' => $path, |
|
61
|
|
|
'login' => $options->getUsername(), |
|
62
|
|
|
'password' => $options->getPassword(), |
|
63
|
|
|
'wt' => 'phps' |
|
64
|
|
|
]; |
|
65
|
|
|
$key = md5(implode(':', $options)); |
|
66
|
|
|
|
|
67
|
|
|
if (!isset($this->clients[$key])) { |
|
68
|
|
|
$this->clients[$key] = new SolrClient($options); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $this->clients[$key]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return ModuleOptions |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getOptions() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->options; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Create new instance for Solr\Manager |
|
84
|
|
|
* @param ServiceLocatorInterface $sl |
|
85
|
|
|
* @return Manager |
|
86
|
|
|
*/ |
|
87
|
|
|
static public function factory(ServiceLocatorInterface $sl) |
|
|
|
|
|
|
88
|
|
|
{ |
|
89
|
|
|
return new static($sl->get('Solr/Options/Module')); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
} |