示例#1
0
 public function saveSchemaTask()
 {
     $pairings = Request::getVar('input', array());
     $pairings = serialize($pairings);
     // The Hubtype
     $type = Request::getVar('type', '');
     $hubType = HubType::all()->where('type', '=', $type)->row();
     $hubType->set('documentMatching', $pairings);
     if (!$hubType->save()) {
         // error
     }
     // Add hubType to search index table
     $queue = IndexQueue::oneOrNew(0);
     $queue->set('hubtype_id', $hubType->get('id'));
     if (!$queue->save()) {
         // error
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=solr&task=searchindex', false), 'Successfully added to index queue.', 'success');
 }
示例#2
0
 /**
  * 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;
 }