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;
 }
Example #2
0
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
ini_set('memory_limit', '50M');
ini_set('max_execution_time', '3600');
require_once 'util.inc.php';
// set up util environment
require_once 'sys/Solr.php';
// Read Config file
$configArray = parse_ini_file('../web/conf/config.ini', true);
// Setup Solr Connection -- Allow core to be specified as first command line param.
$url = $configArray['Index']['url'];
$solr = new Solr($url, isset($argv[1]) ? $argv[1] : '');
if ($configArray['System']['debugSolr']) {
    $solr->debug = true;
}
// Commit and Optimize the Solr Index
$solr->commit();
$solr->optimize();
Example #3
0
 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;
 }