Ejemplo n.º 1
0
 public function matchDocumentSchemaTask()
 {
     // @TODO Verify the HubType is not new, use serialized params input to load last settings.
     $type = Request::getVar('type', '');
     if ($type != '') {
         //$hubSearch = new SearchEngine();
         $helper = new Helper();
         $this->view->typeStructure = $helper->fetchDataTypes(null, $type);
         $searchDocument = array('title' => '', 'doi' => '', 'isbn' => '', 'author' => '', 'created' => '', 'modified' => '', 'scope' => '', 'scope_id' => '', 'fulltext' => '', 'description' => '', 'abstract' => '', 'location' => '', 'uid' => '', 'gid' => '', 'created_by' => '', 'child_id' => '', 'parent_id' => '', 'state' => '', 'hits' => '', 'publish_up' => '', 'publish_down' => '', 'type' => '', 'note' => '', 'keywords' => '', 'language' => '', 'tags' => '', 'badge' => '', 'date' => '', 'year' => '', 'month' => '', 'day' => '', 'address' => '', 'organization' => '', 'name' => '', 'access-level' => '', 'access-group' => '', 'permission-level' => '', 'hub-assoc' => '', 'organization' => '', 'url' => '', 'cms-ranking' => '', 'cms-rating' => '', 'params' => '', 'meta' => '', 'hubID' => '', 'hubURL' => '', 'cms-state' => '');
         $this->view->type = $type;
         $this->view->hubDocument = $searchDocument;
         $this->view->previousSettings = isset($type->documentMatching) && $type->documentMatching != '' ? unserialize($type->documentMatching) : NULL;
         $this->view->setLayout('addDocuments');
         $this->view->display();
     }
 }
Ejemplo n.º 2
0
 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');
 }