SS 4.0 - Upgrade Solr reindex components
This commit is contained in:
parent
4143850786
commit
5fae52374f
|
@ -5,6 +5,11 @@ namespace SilverStripe\FullTextSearch\Solr\Reindex\Handlers;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use SilverStripe\FullTextSearch\Solr\Solr;
|
use SilverStripe\FullTextSearch\Solr\Solr;
|
||||||
use SilverStripe\FullTextSearch\Solr\SolrIndex;
|
use SilverStripe\FullTextSearch\Solr\SolrIndex;
|
||||||
|
use SilverStripe\FullTextSearch\Search\Variants\SearchVariant;
|
||||||
|
use SilverStripe\FullTextSearch\Search\Queries\SearchQuery;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\ORM\DataList;
|
||||||
|
use SilverStripe\ORM\DB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for re-indexing of solr content
|
* Base class for re-indexing of solr content
|
||||||
|
@ -17,7 +22,7 @@ abstract class SolrReindexBase implements SolrReindexHandler
|
||||||
$this->processIndex($logger, $indexInstance, $batchSize, $taskName, $classes);
|
$this->processIndex($logger, $indexInstance, $batchSize, $taskName, $classes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process index for a single SolrIndex instance
|
* Process index for a single SolrIndex instance
|
||||||
*
|
*
|
||||||
|
@ -163,7 +168,7 @@ abstract class SolrReindexBase implements SolrReindexHandler
|
||||||
|
|
||||||
// This will slow down things a tiny bit, but it is done so that we don't timeout to the database during a reindex
|
// This will slow down things a tiny bit, but it is done so that we don't timeout to the database during a reindex
|
||||||
DB::query('SELECT 1');
|
DB::query('SELECT 1');
|
||||||
|
|
||||||
$logger->info("Done");
|
$logger->info("Done");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,11 +186,11 @@ abstract class SolrReindexBase implements SolrReindexHandler
|
||||||
protected function getRecordsInGroup(SolrIndex $indexInstance, $class, $groups, $group)
|
protected function getRecordsInGroup(SolrIndex $indexInstance, $class, $groups, $group)
|
||||||
{
|
{
|
||||||
// Generate filtered list of local records
|
// Generate filtered list of local records
|
||||||
$baseClass = ClassInfo::baseDataClass($class);
|
$baseClass = DataObject::getSchema()->baseDataClass($class);
|
||||||
$items = DataList::create($class)
|
$items = DataList::create($class)
|
||||||
->where(sprintf(
|
->where(sprintf(
|
||||||
'"%s"."ID" %% \'%d\' = \'%d\'',
|
'"%s"."ID" %% \'%d\' = \'%d\'',
|
||||||
$baseClass,
|
DataObject::getSchema()->tableName($baseClass),
|
||||||
intval($groups),
|
intval($groups),
|
||||||
intval($group)
|
intval($group)
|
||||||
))
|
))
|
||||||
|
|
|
@ -4,6 +4,9 @@ namespace SilverStripe\FullTextSearch\Solr\Reindex\Handlers;
|
||||||
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use SilverStripe\FullTextSearch\Solr\SolrIndex;
|
use SilverStripe\FullTextSearch\Solr\SolrIndex;
|
||||||
|
use SilverStripe\FullTextSearch\Solr\Solr;
|
||||||
|
use SilverStripe\ORM\DB;
|
||||||
|
use SilverStripe\Control\Director;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invokes an immediate reindex
|
* Invokes an immediate reindex
|
||||||
|
|
|
@ -4,11 +4,22 @@ namespace SilverStripe\FullTextSearch\Solr\Reindex\Handlers;
|
||||||
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use SilverStripe\FullTextSearch\Solr\SolrIndex;
|
use SilverStripe\FullTextSearch\Solr\SolrIndex;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\ORM\DB;
|
||||||
|
use SilverStripe\Core\Convert;
|
||||||
|
use SilverStripe\Core\Injector\Injector;
|
||||||
|
use SilverStripe\FullTextSearch\Solr\Reindex\Jobs\SolrReindexQueuedJob;
|
||||||
|
use SilverStripe\FullTextSearch\Solr\Reindex\Jobs\SolrReindexGroupQueuedJob;
|
||||||
|
use SilverStripe\FullTextSearch\Search\Processors\SearchUpdateCommitJobProcessor;
|
||||||
|
|
||||||
if (!interface_exists('QueuedJob')) {
|
if (!interface_exists('SilverStripe\QueuedJobs\Services\QueuedJob')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use SilverStripe\QueuedJobs\Services\QueuedJob;
|
||||||
|
use SilverStripe\QueuedJobs\Services\QueuedJobService;
|
||||||
|
use SilverStripe\QueuedJobs\DataObjects\QueuedJobDescriptor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a queued task to start the reindex job
|
* Represents a queued task to start the reindex job
|
||||||
*/
|
*/
|
||||||
|
@ -19,7 +30,7 @@ class SolrReindexQueuedHandler extends SolrReindexBase
|
||||||
*/
|
*/
|
||||||
protected function getQueuedJobService()
|
protected function getQueuedJobService()
|
||||||
{
|
{
|
||||||
return singleton('QueuedJobService');
|
return singleton(QueuedJobService::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,7 +44,7 @@ class SolrReindexQueuedHandler extends SolrReindexBase
|
||||||
$clearable = array(
|
$clearable = array(
|
||||||
// Paused jobs need to be discarded
|
// Paused jobs need to be discarded
|
||||||
QueuedJob::STATUS_PAUSED,
|
QueuedJob::STATUS_PAUSED,
|
||||||
|
|
||||||
// These types would be automatically started
|
// These types would be automatically started
|
||||||
QueuedJob::STATUS_NEW,
|
QueuedJob::STATUS_NEW,
|
||||||
QueuedJob::STATUS_WAIT,
|
QueuedJob::STATUS_WAIT,
|
||||||
|
@ -43,27 +54,28 @@ class SolrReindexQueuedHandler extends SolrReindexBase
|
||||||
QueuedJob::STATUS_RUN
|
QueuedJob::STATUS_RUN
|
||||||
);
|
);
|
||||||
DB::query(sprintf(
|
DB::query(sprintf(
|
||||||
'UPDATE "QueuedJobDescriptor" '
|
'UPDATE "%s" '
|
||||||
. ' SET "JobStatus" = \'%s\''
|
. ' SET "JobStatus" = \'%s\''
|
||||||
. ' WHERE "JobStatus" IN (\'%s\')'
|
. ' WHERE "JobStatus" IN (\'%s\')'
|
||||||
. ' AND "Implementation" = \'%s\'',
|
. ' AND "Implementation" = \'%s\'',
|
||||||
|
Convert::raw2sql(DataObject::getSchema()->tableName(QueuedJobDescriptor::class)),
|
||||||
Convert::raw2sql(QueuedJob::STATUS_CANCELLED),
|
Convert::raw2sql(QueuedJob::STATUS_CANCELLED),
|
||||||
implode("','", Convert::raw2sql($clearable)),
|
implode("','", Convert::raw2sql($clearable)),
|
||||||
Convert::raw2sql($type)
|
Convert::raw2sql($type)
|
||||||
));
|
));
|
||||||
return DB::affectedRows();
|
return DB::affected_rows();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function triggerReindex(LoggerInterface $logger, $batchSize, $taskName, $classes = null)
|
public function triggerReindex(LoggerInterface $logger, $batchSize, $taskName, $classes = null)
|
||||||
{
|
{
|
||||||
// Cancel existing jobs
|
// Cancel existing jobs
|
||||||
$queues = $this->cancelExistingJobs('SolrReindexQueuedJob');
|
$queues = $this->cancelExistingJobs(SolrReindexQueuedJob::class);
|
||||||
$groups = $this->cancelExistingJobs('SolrReindexGroupQueuedJob');
|
$groups = $this->cancelExistingJobs(SolrReindexGroupQueuedJob::class);
|
||||||
$logger->info("Cancelled {$queues} re-index tasks and {$groups} re-index groups");
|
$logger->info("Cancelled {$queues} re-index tasks and {$groups} re-index groups");
|
||||||
|
|
||||||
// Although this class is used as a service (singleton) it may also be instantiated
|
// Although this class is used as a service (singleton) it may also be instantiated
|
||||||
// as a queuedjob
|
// as a queuedjob
|
||||||
$job = Injector::inst()->create('SolrReindexQueuedJob', $batchSize, $taskName, $classes);
|
$job = Injector::inst()->create(SolrReindexQueuedJob::class, $batchSize, $taskName, $classes);
|
||||||
$this
|
$this
|
||||||
->getQueuedJobService()
|
->getQueuedJobService()
|
||||||
->queueJob($job);
|
->queueJob($job);
|
||||||
|
@ -77,13 +89,13 @@ class SolrReindexQueuedHandler extends SolrReindexBase
|
||||||
) {
|
) {
|
||||||
// Trigger another job for this group
|
// Trigger another job for this group
|
||||||
$job = Injector::inst()->create(
|
$job = Injector::inst()->create(
|
||||||
'SolrReindexGroupQueuedJob',
|
SolrReindexGroupQueuedJob::class,
|
||||||
get_class($indexInstance), $state, $class, $groups, $group
|
get_class($indexInstance), $state, $class, $groups, $group
|
||||||
);
|
);
|
||||||
$this
|
$this
|
||||||
->getQueuedJobService()
|
->getQueuedJobService()
|
||||||
->queueJob($job);
|
->queueJob($job);
|
||||||
|
|
||||||
$title = $job->getTitle();
|
$title = $job->getTitle();
|
||||||
$logger->info("Queued {$title}");
|
$logger->info("Queued {$title}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace SilverStripe\FullTextSearch\Solr\Reindex\Jobs;
|
namespace SilverStripe\FullTextSearch\Solr\Reindex\Jobs;
|
||||||
if (!interface_exists('QueuedJob')) {
|
|
||||||
|
if (!interface_exists('SilverStripe\QueuedJobs\Services\QueuedJob')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace SilverStripe\FullTextSearch\Solr\Reindex\Jobs;
|
namespace SilverStripe\FullTextSearch\Solr\Reindex\Jobs;
|
||||||
if (!interface_exists('QueuedJob')) {
|
|
||||||
|
if (!interface_exists('SilverStripe\QueuedJobs\Services\QueuedJob')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace SilverStripe\FullTextSearch\Solr\Reindex\Jobs;
|
namespace SilverStripe\FullTextSearch\Solr\Reindex\Jobs;
|
||||||
|
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use SilverStripe\Core\Injector\Injector;
|
||||||
|
use SilverStripe\FullTextSearch\Solr\Reindex\Handlers\SolrReindexHandler;
|
||||||
|
use SilverStripe\FullTextSearch\Utils\Logging\SearchLogFactory;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
if (!interface_exists('QueuedJob')) {
|
if (!interface_exists('SilverStripe\QueuedJobs\Services\QueuedJob')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use SilverStripe\QueuedJobs\Services\QueuedJob;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for jobs which perform re-index
|
* Base class for jobs which perform re-index
|
||||||
*/
|
*/
|
||||||
|
@ -44,7 +52,7 @@ abstract class SolrReindexQueuedJobBase implements QueuedJob
|
||||||
*/
|
*/
|
||||||
protected function getLoggerFactory()
|
protected function getLoggerFactory()
|
||||||
{
|
{
|
||||||
return Injector::inst()->get('SearchLogFactory');
|
return Injector::inst()->get(SearchLogFactory::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,7 +111,7 @@ abstract class SolrReindexQueuedJobBase implements QueuedJob
|
||||||
*/
|
*/
|
||||||
protected function getHandler()
|
protected function getHandler()
|
||||||
{
|
{
|
||||||
return Injector::inst()->get('SolrReindexHandler');
|
return Injector::inst()->get(SolrReindexHandler::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function jobFinished()
|
public function jobFinished()
|
||||||
|
|
Loading…
Reference in New Issue