mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 14:05:29 +02:00
Merge pull request #179 from creative-commoners/pulls/3.0/env-var-support
NEW Support environment variables for Solr index prefix and suffix
This commit is contained in:
commit
71d837d7b0
@ -3,6 +3,7 @@
|
|||||||
namespace SilverStripe\FullTextSearch\Solr;
|
namespace SilverStripe\FullTextSearch\Solr;
|
||||||
|
|
||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Control\Director;
|
||||||
|
use SilverStripe\Core\Environment;
|
||||||
use SilverStripe\FulltextSearch\Search\Indexes\SearchIndex;
|
use SilverStripe\FulltextSearch\Search\Indexes\SearchIndex;
|
||||||
use SilverStripe\FullTextSearch\Solr\Services\SolrService;
|
use SilverStripe\FullTextSearch\Solr\Services\SolrService;
|
||||||
use SilverStripe\FulltextSearch\Search\Queries\SearchQuery;
|
use SilverStripe\FulltextSearch\Search\Queries\SearchQuery;
|
||||||
@ -108,16 +109,17 @@ abstract class SolrIndex extends SearchIndex
|
|||||||
public function getIndexName()
|
public function getIndexName()
|
||||||
{
|
{
|
||||||
$name = get_class($this);
|
$name = get_class($this);
|
||||||
|
$indexParts = [$name];
|
||||||
|
|
||||||
if (defined('SS_SOLR_INDEX_PREFIX')) {
|
if ($indexPrefix = Environment::getEnv('SS_SOLR_INDEX_PREFIX')) {
|
||||||
$name = SS_SOLR_INDEX_PREFIX . ''. $name;
|
array_unshift($indexParts, $indexPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined('SS_SOLR_INDEX_SUFFIX')) {
|
if ($indexSuffix = Environment::getEnv('SS_SOLR_INDEX_SUFFIX')) {
|
||||||
$name = $name . '' . SS_SOLR_INDEX_SUFFIX;
|
$indexParts[] = $indexSuffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $name;
|
return implode($indexParts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTypes()
|
public function getTypes()
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace SilverStripe\FullTextSearch\Tests;
|
namespace SilverStripe\FullTextSearch\Tests;
|
||||||
|
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
|
use SilverStripe\Core\Environment;
|
||||||
use SilverStripe\Core\Injector\Injector;
|
use SilverStripe\Core\Injector\Injector;
|
||||||
use SilverStripe\Core\Kernel;
|
use SilverStripe\Core\Kernel;
|
||||||
use SilverStripe\Dev\SapphireTest;
|
use SilverStripe\Dev\SapphireTest;
|
||||||
@ -337,6 +338,22 @@ class SolrIndexTest extends SapphireTest
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetIndexName()
|
||||||
|
{
|
||||||
|
$index = new SolrIndexTest_FakeIndex2;
|
||||||
|
$this->assertSame(SolrIndexTest_FakeIndex2::class, $index->getIndexName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetIndexNameWithPrefixAndSuffixFromEnvironment()
|
||||||
|
{
|
||||||
|
$index = new SolrIndexTest_FakeIndex2;
|
||||||
|
|
||||||
|
Environment::putEnv('SS_SOLR_INDEX_PREFIX="foo_"');
|
||||||
|
Environment::putEnv('SS_SOLR_INDEX_SUFFIX="_bar"');
|
||||||
|
|
||||||
|
$this->assertSame('foo_' . SolrIndexTest_FakeIndex2::class . '_bar', $index->getIndexName());
|
||||||
|
}
|
||||||
|
|
||||||
protected function getFakeRawSolrResponse()
|
protected function getFakeRawSolrResponse()
|
||||||
{
|
{
|
||||||
return new \Apache_Solr_Response(
|
return new \Apache_Solr_Response(
|
||||||
|
Loading…
Reference in New Issue
Block a user