nyeholt / silverstripe-solr

SilverStripe and Solr integration ssaumodule
BSD 3-Clause "New" or "Revised" License
19 stars 18 forks source link

SolrReindexTask should not delete each type if only queueing tasks. #57

Open silbinarywolf opened 7 years ago

silbinarywolf commented 7 years ago

SolrReindexTask just needs:

 $search->getSolr()->deleteByQuery('ClassNameHierarchy_ms:' . $type);

Moved to the non-QueuedJobs codepath.


SolrReindexJob

public function setup() {
    $this->lastIndexedID = 0;
    $service = singleton('SolrSearchService');
    $service->getSolr()->deleteByQuery('ClassNameHierarchy_ms:' . $this->reindexType);
}

SolrReindexTask


foreach ($this->types as $type) {
    $search->getSolr()->deleteByQuery('ClassNameHierarchy_ms:' . $type);
    $search->getSolr()->commit();

    if (ClassInfo::exists('QueuedJob') && !isset($_GET['direct'])) {
        $job = new SolrReindexJob($type);
        $svc = singleton('QueuedJobService');
        $svc->queueJob($job);
        $this->log("Reindexing job for $type has been queued");
    } else {

        $mode = Versioned::get_reading_mode();
        Versioned::reading_stage('Stage');

        // get the holders first, see if we have any that AREN'T in the root (ie we've already partitioned everything...)
        $pages = $type::get();
        $pages = $pages->filter(array('ClassName' => $type));

        /* @var $search SolrSearchService */
        $this->log("------------------------------");
        $this->log("Start reindexing job for $type (Count: ".$pages->count()."):");
        $this->log("------------------------------");
        foreach ($pages as $page) {