2011-05-02 06:33:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
Solr::include_client_api();
|
|
|
|
|
|
|
|
class SolrService extends Apache_Solr_Service {
|
|
|
|
|
2012-07-19 17:17:30 +02:00
|
|
|
/**
|
|
|
|
* @return Apache_Solr_Response
|
|
|
|
*/
|
2011-05-02 06:33:05 +02:00
|
|
|
protected function coreCommand($command, $core, $params=array()) {
|
|
|
|
$command = strtoupper($command);
|
|
|
|
|
|
|
|
$params = array_merge($params, array('action' => $command, 'wt' => 'json'));
|
|
|
|
$params[$command == 'CREATE' ? 'name' : 'core'] = $core;
|
|
|
|
|
|
|
|
return $this->_sendRawGet($this->_constructUrl('admin/cores', $params));
|
|
|
|
}
|
|
|
|
|
2012-07-19 17:17:30 +02:00
|
|
|
/**
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2011-05-02 06:33:05 +02:00
|
|
|
public function coreIsActive($core) {
|
|
|
|
$result = $this->coreCommand('STATUS', $core);
|
|
|
|
return isset($result->status->$core->uptime);
|
|
|
|
}
|
|
|
|
|
2012-07-19 17:17:30 +02:00
|
|
|
/**
|
|
|
|
* @return Apache_Solr_Response
|
|
|
|
*/
|
2011-05-02 06:33:05 +02:00
|
|
|
public function coreCreate($core, $instancedir, $config=null, $schema=null, $datadir=null) {
|
|
|
|
$args = array('instanceDir' => $instancedir);
|
|
|
|
if ($config) $args['config'] = $config;
|
|
|
|
if ($schema) $args['schema'] = $schema;
|
|
|
|
if ($datadir) $args['dataDir'] = $datadir;
|
|
|
|
|
2012-07-19 17:17:30 +02:00
|
|
|
return $this->coreCommand('CREATE', $core, $args);
|
2011-05-02 06:33:05 +02:00
|
|
|
}
|
|
|
|
|
2012-07-19 17:17:30 +02:00
|
|
|
/**
|
|
|
|
* @return Apache_Solr_Response
|
|
|
|
*/
|
2011-05-02 06:33:05 +02:00
|
|
|
public function coreReload($core) {
|
2012-07-19 17:17:30 +02:00
|
|
|
return $this->coreCommand('RELOAD', $core);
|
2011-05-02 06:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected $_serviceCache = array();
|
|
|
|
|
|
|
|
public function serviceForCore($core) {
|
|
|
|
if (!isset($this->_serviceCache[$core])) {
|
|
|
|
$this->_serviceCache[$core] = new Apache_Solr_Service($this->_host, $this->_port, $this->_path."$core", $this->_httpTransport);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->_serviceCache[$core];
|
|
|
|
}
|
|
|
|
}
|