Example #1
0
 public function searchTask()
 {
     $searchRequest = Request::getVar('search', array());
     $query = $searchRequest['query'];
     $HubtypeFilter = $searchRequest['type'];
     $hubSearch = new SearchEngine();
     if ($HubtypeFilter != '') {
         //$search = $hubSearch->createFilterQuery('hubtype')->setQuery('hubtype:'.$HubtypeFilter)->search($query)->limit(100);
         $search = $hubSearch->search($query)->limit(100);
     } else {
         $search = $hubSearch->search($query)->limit(100);
     }
     $result = $search->getResult();
     $response = new stdClass();
     $response->results = $result;
     $response->search = $search;
     $response->queryString = $query;
     return $this->displayTask($response);
 }
Example #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');
 }