function saveToSolr($quick = false) { if ($this->saveStarted) { return true; } $this->saveStarted = true; global $timer; global $configArray; $this->_quickReindex = $quick; $host = $configArray[$this->getConfigSection()]['url']; global $logger; $logger->log("Updating " . $this->solrId() . " in solr", PEAR_LOG_INFO); $cores = $this->cores(); $objectStructure = $this->getObjectStructure(); $doc = array(); foreach ($objectStructure as $property) { if ($property['storeSolr']) { $propertyName = $property['property']; if ($property['type'] == 'method') { $methodName = isset($property['methodName']) ? $property['methodName'] : $property['property']; $doc[$propertyName] = $this->{$methodName}(); } elseif ($property['type'] == 'crSeparated') { if (strlen($this->{$propertyName})) { $propertyValues = explode("\r\n", $this->{$propertyName}); $doc[$propertyName] = $propertyValues; } } elseif ($property['type'] == 'date' || $property['type'] == 'partialDate') { if ($this->{$propertyName} != null && strlen($this->{$propertyName}) > 0) { //get the date array and reformat for solr $dateParts = date_parse($this->{$propertyName}); if ($dateParts['year'] != false && $dateParts['month'] != false && $dateParts['day'] != false) { $time = $dateParts['year'] . '-' . $dateParts['month'] . '-' . $dateParts['day'] . 'T00:00:00Z'; $doc[$propertyName] = $time; } } } else { if (isset($this->{$propertyName})) { $doc[$propertyName] = $this->{$propertyName}; } } } } $timer->logTime('Built Contents to save to Solr'); foreach ($cores as $corename) { $index = new Solr($host, $corename); $xml = $index->getSaveXML($doc, !$this->_quickReindex, $this->_quickReindex); //$logger->log('XML ' . print_r($xml, true), PEAR_LOG_INFO); $timer->logTime('Created XML to save to the main index'); if ($index->saveRecord($xml)) { if (!$this->_quickReindex) { $result = $index->commit(); //$logger->log($xml, PEAR_LOG_INFO); //$logger->log("Result saving to $corename index " . print_r($result, true), PEAR_LOG_INFO); } } else { $this->saveStarted = false; return new PEAR_Error("Could not save to {$corename}"); } $timer->logTime("Saved to the {$corename} index"); } $this->saveStarted = false; return true; }
function saveToSolr($quick = false) { if ($this->saveStarted) { return true; } $this->saveStarted = true; global $timer; global $configArray; $this->_quickReindex = $quick; $host = $configArray[$this->getConfigSection()]['url']; global $logger; $logger->log("Updating " . $this->solrId() . " in solr", PEAR_LOG_INFO); $cores = $this->cores(); $objectStructure = $this->getObjectStructure(); $doc = array(); foreach ($objectStructure as $property) { if (isset($property['storeSolr']) && $property['storeSolr'] || isset($property['properties']) && count($property['properties']) > 0) { $doc = $this->updateSolrDocumentForProperty($doc, $property); } } $timer->logTime('Built Contents to save to Solr'); foreach ($cores as $corename) { $index = new Solr($host, $corename); $xml = $index->getSaveXML($doc, !$this->_quickReindex, $this->_quickReindex); //$logger->log('XML ' . print_r($xml, true), PEAR_LOG_INFO); $timer->logTime('Created XML to save to the main index'); if ($index->saveRecord($xml)) { if (!$this->_quickReindex) { $result = $index->commit(); //$logger->log($xml, PEAR_LOG_INFO); //$logger->log("Result saving to $corename index " . print_r($result, true), PEAR_LOG_INFO); } } else { $this->saveStarted = false; return new PEAR_Error("Could not save to {$corename}"); } $timer->logTime("Saved to the {$corename} index"); } $this->saveStarted = false; return true; }