Merge pull request #206 from jakedaleweb/master
Fix issue where schema.xml etc is put in a different dir than the cor…
This commit is contained in:
commit
4db4a2bbb5
|
@ -21,12 +21,7 @@ class SolrService extends SolrService_Core
|
|||
*/
|
||||
protected function coreCommand($command, $core, $params = array())
|
||||
{
|
||||
// Unencode the class name
|
||||
$core = SolrIndex::getClassNameFromIndex($core);
|
||||
|
||||
$command = strtoupper($command);
|
||||
//get the non-namespaced name of the Solr core, since backslashes not valid characters
|
||||
$core = ClassInfo::shortName($core);
|
||||
$params = array_merge($params, array('action' => $command, 'wt' => 'json'));
|
||||
$params[$command == 'CREATE' ? 'name' : 'core'] = $core;
|
||||
|
||||
|
@ -40,17 +35,9 @@ class SolrService extends SolrService_Core
|
|||
*/
|
||||
public function coreIsActive($core)
|
||||
{
|
||||
// Unencode the class name
|
||||
$core = SolrIndex::getClassNameFromIndex($core);
|
||||
|
||||
// Request the status of the full core name
|
||||
$result = $this->coreCommand('STATUS', $core);
|
||||
|
||||
// Solr returns the core as the 'short name' of the class (e.g. Mysite\Search\SolrIndex -> SolrIndex)
|
||||
$reflection = new \ReflectionClass($core);
|
||||
$shortClass = $reflection->getShortName();
|
||||
|
||||
return isset($result->status->$shortClass->uptime);
|
||||
return isset($result->status->$core->uptime);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,17 +76,13 @@ class SolrService extends SolrService_Core
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a new Solr3Service_Core instance for the passed core
|
||||
* Create a new Solr4Service_Core instance for the passed core
|
||||
* @param $core string - The name of the core
|
||||
* @return Solr3Service_Core
|
||||
* @return Solr4Service_Core
|
||||
*/
|
||||
public function serviceForCore($core)
|
||||
{
|
||||
// Unencode the class name
|
||||
$core = SolrIndex::getClassNameFromIndex($core);
|
||||
|
||||
$klass = Config::inst()->get(get_called_class(), 'core_class');
|
||||
$coreName = ClassInfo::shortName($core);
|
||||
return new $klass($this->_host, $this->_port, $this->_path . $coreName, $this->_httpTransport);
|
||||
return new $klass($this->_host, $this->_port, $this->_path . $core, $this->_httpTransport);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,29 +124,6 @@ abstract class SolrIndex extends SearchIndex
|
|||
return implode($indexParts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for returning the indexer class name from an index name, encoded via {@link getIndexName()}
|
||||
*
|
||||
* @param string $indexName
|
||||
* @return string
|
||||
*/
|
||||
public static function getClassNameFromIndex($indexName)
|
||||
{
|
||||
if (($indexPrefix = Environment::getEnv('SS_SOLR_INDEX_PREFIX'))
|
||||
&& (substr($indexName, 0, strlen($indexPrefix)) === $indexPrefix)
|
||||
) {
|
||||
$indexName = substr($indexName, strlen($indexPrefix));
|
||||
}
|
||||
|
||||
if (($indexSuffix = Environment::getEnv('SS_SOLR_INDEX_SUFFIX'))
|
||||
&& (substr($indexName, -strlen($indexSuffix)) === $indexSuffix)
|
||||
) {
|
||||
$indexName = substr($indexName, 0, -strlen($indexSuffix));
|
||||
}
|
||||
|
||||
return str_replace('-', '\\', $indexName);
|
||||
}
|
||||
|
||||
public function getTypes()
|
||||
{
|
||||
return $this->renderWith($this->getTemplatesPath() . '/types.ss');
|
||||
|
|
|
@ -376,30 +376,6 @@ class SolrIndexTest extends SapphireTest
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider indexNameProvider
|
||||
* @param string $indexName
|
||||
* @param string $expected
|
||||
*/
|
||||
public function testGetClassNameFromIndex($indexName, $expected)
|
||||
{
|
||||
Environment::putEnv('SS_SOLR_INDEX_PREFIX="foo_"');
|
||||
Environment::putEnv('SS_SOLR_INDEX_SUFFIX="_bar"');
|
||||
|
||||
$this->assertSame($expected, SolrIndex::getClassNameFromIndex($indexName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public function indexNameProvider()
|
||||
{
|
||||
return [
|
||||
['foo_SilverStripe-FullTextSearch-Tests-SolrIndexTest_bar', __CLASS__],
|
||||
['SilverStripe-FullTextSearch-Tests-SolrIndexTest', __CLASS__],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getFakeRawSolrResponse()
|
||||
{
|
||||
return new \Apache_Solr_Response(
|
||||
|
|
Loading…
Reference in New Issue