/** * Insert database records into the search Index * * @param object $job \Components\Cron\Models\Job * @return boolean */ public function processQueue(\Components\Cron\Models\Job $job) { // Get the relevant models require_once PATH_CORE . DS . 'components' . DS . 'com_search' . DS . 'models' . DS . 'indexqueue.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_search' . DS . 'models' . DS . 'hubtype.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_search' . DS . 'models' . DS . 'noindex.php'; // A counter for the number of documents indexed $indexedDocuments = 0; // Get the type needed to be indexed; $item = IndexQueue::all()->where('indexed', '=', 0)->limit(1)->row(); $hubTypeID = $item->get('hubtype_id', 0); // @TODO relational $hubType = HubType::oneOrFail($hubTypeID); $noIndex = NoIndex::all()->select('hubid')->where('hubtype', '=', $hubType->get('type'))->rows()->toArray(); $blacklist = array(); foreach ($noIndex as $key => $value) { array_push($blacklist, $value['hubid']); } $mapping = unserialize($hubType->get('documentMatching')); // Get rows, limit 400 $rows = $this->getRows($hubType, 100); $hubSearch = new SolrEngine(); $queryString = 'hubtype:' . $hubType->get('type'); $existingRecords = $hubSearch->search($queryString)->getResult(); $existingTable = array(); foreach ($existingRecords->getDocuments() as $document) { $existingTable[$document['hubid']] = $document['id']; } foreach ($rows as $row) { $id = is_array($row) ? $row['id'] : $row->id; if (in_array($id, $blacklist) === FALSE) { // Create blank object $document = new stdClass(); foreach ($mapping as $field => $searchField) { // Ensure the searchField is not empty if ($searchField != '') { // Normalize the fieldname $searchField = strtolower($searchField); $document->{$searchField} = is_array($row) ? $row[$field] : $row->{$field}; } } // Add the unique hubtype $document->hubtype = $hubType->get('type'); // Update or add if (in_array($id, array_keys($existingTable))) { $docID = $existingTable[$id]; } else { $docID = null; } // Verify that it indexed properly if ($hubSearch->add($document, $docID)) { $indexedDocuments++; } } } // Calculate offset $count = $this->getRows($hubType, null, TRUE); if ($count == $indexedDocuments + count($blacklist)) { $item->set('indexed', 1); $item->set('indexed_on', Date::of()->toSql()); } else { $item->set('offset', $indexedDocuments); } $item->save(); return true; }
public function fetchDataTypes($config, $type = '') { if ($type == '') { $hubTypes = HubType::all(); $typeDescription = array(); foreach ($hubTypes as $type) { require_once PATH_ROOT . DS . $type->file_path; $classpath = $type->class_path; if (strpos($classpath, 'Tables') === FALSE) { $model = new $classpath(); } else { $database = App::get('db'); $model = new $classpath($database); } if (is_subclass_of($model, 'Relational')) { // Get local model fields $modelStructure = $type->structure(); // Get related model fields $relationships = $model->introspectRelationships(); $modelName = $type->get('type'); // Add the related and local fields array_push($typeDescription, array('name' => $modelName, 'structure' => $modelStructure)); } } // End foreach } else { $typeDescription = array(); $type = HubType::all()->where('type', '=', $type)->row(); require_once PATH_ROOT . DS . $type->file_path; $classpath = $type->class_path; if (strpos($classpath, 'Tables') === FALSE) { $model = new $classpath(); } else { $database = App::get('db'); $model = new $classpath($database); } // Get local model fields $modelStructure = $type->structure(); // Get related model fields //$relationships = $model->introspectRelationships(); $modelName = $type->get('type'); // Add the related and local fields array_push($typeDescription, array('name' => $modelName, 'structure' => $modelStructure)); } return $typeDescription; }