public function saveSchemaTask() { /** * This method depends on an array of pairings * which match the Solr Schema to database fields. * @TODO Save serialized input array to Hubtype params field **/ $pairings = Request::getVar('input', array()); // The Hubtype $type = Request::getVar('type', ''); // Instatiate helper $helper = new Helper(); $rows = $helper->fetchHubTypeRows($type); // Some informative counters $docCount = 0; $updateCount = 0; $noIndexCount = 0; $removedCount = 0; // The blacklist $noIndex = new Noindex(); $noIndex = $noIndex->all()->where('hubtype', '=', $type)->rows(); $blacklist = $noIndex->fieldsByKey('hubid'); foreach ($rows as $row) { $id = get_class($row) != 'stdClass' ? $row->get('id') : $row->id; if (!in_array($id, $blacklist)) { $hubSearch = new SearchEngine(); $document = new stdClass(); foreach ($pairings as $solrField => $hubField) { if (get_class($row) != 'stdClass') { $document->{$solrField} = $row->get($hubField, ''); } else { $document->{$solrField} = $row->{$hubField}; } } $document->hubtype = $type; if (get_class($row) == 'stdClass') { $document->hubid = $row->id; } else { $document->hubid = $row->get('id'); } // Check for duplicates, updated $query = 'hubtype:' . $type . ' AND hubid:' . $document->hubid; $duplicates = $hubSearch->search($query)->getResult(); if ($duplicates->count() == 0) { $solrID = NULL; $docCount++; } elseif ($duplicates->count() > 0) { foreach ($duplicates->getDocuments() as $dup) { $solrID = $dup->getFields()['id']; $updateCount++; } } else { $solrID = NULL; } $hubSearch->add($document, $solrID); } else { $noIndexCount++; } } App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=documentByType&type=' . $type, false), 'Successfully indexed ' . $docCount . ' documents; updated ' . $updateCount . ' documents; ignored ' . $noIndexCount . ' documents.', 'success'); }