From 9e51c1632c7338898bd1672cf1342779d5f6a1fb Mon Sep 17 00:00:00 2001 From: John Milmine Date: Tue, 22 Mar 2016 22:13:46 +1300 Subject: [PATCH] adding ability for solr suffix and prefixing This means the same code can run on a single solr core and have the same indexes but use prefixes or suffixes to keep them separate --- code/solr/SolrIndex.php | 18 +++++++++++++++++- .../handlers/SolrReindexImmediateHandler.php | 5 +++-- .../handlers/SolrReindexQueuedHandler.php | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/code/solr/SolrIndex.php b/code/solr/SolrIndex.php index 3c9bd1e..49e1dc8 100644 --- a/code/solr/SolrIndex.php +++ b/code/solr/SolrIndex.php @@ -80,9 +80,25 @@ abstract class SolrIndex extends SearchIndex return $this->renderWith($this->getTemplatesPath() . '/schema.ss'); } + /** + * Helper for returning the correct index name. Supports prefixing and + * suffixing + * + * @return string + */ public function getIndexName() { - return get_class($this); + $name = get_class($this); + + if(defined('SS_SOLR_INDEX_PREFIX')) { + $name = SS_SOLR_INDEX_PREFIX . ''. $name; + } + + if(defined('SS_SOLR_INDEX_SUFFIX')) { + $name = $name . '' . SS_SOLR_INDEX_SUFFIX; + } + + return $name; } public function getTypes() diff --git a/code/solr/reindex/handlers/SolrReindexImmediateHandler.php b/code/solr/reindex/handlers/SolrReindexImmediateHandler.php index 8026a28..ae5ef73 100644 --- a/code/solr/reindex/handlers/SolrReindexImmediateHandler.php +++ b/code/solr/reindex/handlers/SolrReindexImmediateHandler.php @@ -52,9 +52,10 @@ class SolrReindexImmediateHandler extends SolrReindexBase // Build script $indexName = $indexInstance->getIndexName(); + $indexClass = get_class($indexInstance); $scriptPath = sprintf("%s%sframework%scli-script.php", BASE_PATH, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR); $scriptTask = "php {$scriptPath} dev/tasks/{$taskName}"; - $cmd = "{$scriptTask} index={$indexName} class={$class} group={$group} groups={$groups} variantstate={$statevar}"; + $cmd = "{$scriptTask} index={$indexClass} class={$class} group={$group} groups={$groups} variantstate={$statevar}"; $cmd .= " verbose=1 2>&1"; $logger->info("Running '$cmd'"); @@ -66,7 +67,7 @@ class SolrReindexImmediateHandler extends SolrReindexBase // If we're in dev mode, commit more often for fun and profit if (Director::isDev()) { - Solr::service(get_class($indexInstance))->commit(); + Solr::service($indexClass)->commit(); } // This will slow down things a tiny bit, but it is done so that we don't timeout to the database during a reindex diff --git a/code/solr/reindex/handlers/SolrReindexQueuedHandler.php b/code/solr/reindex/handlers/SolrReindexQueuedHandler.php index 25e4b8f..63e8d7e 100644 --- a/code/solr/reindex/handlers/SolrReindexQueuedHandler.php +++ b/code/solr/reindex/handlers/SolrReindexQueuedHandler.php @@ -75,7 +75,7 @@ class SolrReindexQueuedHandler extends SolrReindexBase // Trigger another job for this group $job = Injector::inst()->create( 'SolrReindexGroupQueuedJob', - $indexInstance->getIndexName(), $state, $class, $groups, $group + get_class($indexInstance), $state, $class, $groups, $group ); $this ->getQueuedJobService()