2011-05-02 06:33:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
Solr::include_client_api();
|
|
|
|
|
2013-11-08 01:12:43 +01:00
|
|
|
/**
|
|
|
|
* The API for accessing a specific core of a Solr server. Exactly the same as Apache_Solr_Service for now.
|
|
|
|
*/
|
|
|
|
class SolrService_Core extends Apache_Solr_Service {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The API for accessing the primary Solr installation, which includes both SolrService_Core,
|
|
|
|
* plus extra methods for interrogating, creating, reloading and getting SolrService_Core instances
|
|
|
|
* for Solr cores.
|
|
|
|
*/
|
|
|
|
class SolrService extends SolrService_Core {
|
|
|
|
private static $core_class = 'SolrService_Core';
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2012-07-19 17:17:30 +02:00
|
|
|
/**
|
2013-11-08 01:12:43 +01:00
|
|
|
* Handle encoding the GET parameters and making the HTTP call to execute a core command
|
2012-07-19 17:17:30 +02:00
|
|
|
*/
|
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
|
|
|
/**
|
2013-11-08 01:12:43 +01:00
|
|
|
* Is the passed core active?
|
|
|
|
* @param $core string - The name of the core
|
|
|
|
* @return boolean - True if that core exists & is active
|
2012-07-19 17:17:30 +02:00
|
|
|
*/
|
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
|
|
|
/**
|
2013-11-08 01:12:43 +01:00
|
|
|
* Create a new core
|
|
|
|
* @param $core string - The name of the core
|
|
|
|
* @param $instancedir string - The base path of the core on the server
|
|
|
|
* @param $config string - The filename of solrconfig.xml on the server. Default is $instancedir/solrconfig.xml
|
|
|
|
* @param $schema string - The filename of schema.xml on the server. Default is $instancedir/schema.xml
|
|
|
|
* @param $datadir string - The path to store data for this core on the server. Default depends on solrconfig.xml
|
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
|
|
|
/**
|
2013-11-08 01:12:43 +01:00
|
|
|
* Reload a core
|
|
|
|
* @param $core string - The name of the core
|
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
|
|
|
}
|
|
|
|
|
2013-11-08 01:12:43 +01:00
|
|
|
/**
|
|
|
|
* Create a new Solr3Service_Core instance for the passed core
|
|
|
|
* @param $core string - The name of the core
|
|
|
|
* @return Solr3Service_Core
|
|
|
|
*/
|
2011-05-02 06:33:05 +02:00
|
|
|
public function serviceForCore($core) {
|
2013-11-08 01:12:43 +01:00
|
|
|
$klass = Config::inst()->get(get_called_class(), 'core_class');
|
|
|
|
return new $klass($this->_host, $this->_port, $this->_path.$core, $this->_httpTransport);
|
2011-05-02 06:33:05 +02:00
|
|
|
}
|
|
|
|
}
|