예제 #1
0
 /**
  * Submit an advanced search query.  Responds with JSON results.
  *
  * @param query The Lucene query to perform
  * @param solrOffset The offset into the actual solr results
  * @param displayOffset The offset of actually displayed items
  * @param limit The limit of the result set
  */
 public function submitAction()
 {
     $this->disableLayout();
     $this->disableView();
     $query = $this->getParam('query');
     // Extract <element>.<qualifier> from between '-' and ':' in '<type>-<element>.<qualifier>: <value>'
     $query = preg_replace_callback('/(?<=-)[\\w. ]*(?=:)/', array(&$this, 'strReplaceSpaces'), $query);
     $limit = (int) $this->getParam('limit');
     $solrOffset = (int) $this->getParam('solrOffset');
     $displayOffset = (int) $this->getParam('displayOffset');
     $itemIds = array();
     try {
         $index = $this->ModuleComponent->Solr->getSolrIndex();
         UtilityComponent::beginIgnoreWarnings();
         // underlying library can generate warnings, we need to eat them
         $response = $index->search($query, $solrOffset, $limit * 5, array('fl' => '*,score'));
         // extend limit to allow some room for policy filtering
         UtilityComponent::endIgnoreWarnings();
         $totalResults = $response->response->numFound;
         foreach ($response->response->docs as $doc) {
             $itemIds[] = $doc->key;
         }
     } catch (Exception $e) {
         echo JsonComponent::encode(array('status' => 'error', 'message' => 'Syntax error in query ' . $e->getMessage()));
         return;
     }
     $items = array();
     $count = 0;
     foreach ($itemIds as $itemId) {
         ++$solrOffset;
         $item = $this->Item->load($itemId);
         if ($item && $this->Item->policyCheck($item, $this->userSession->Dao)) {
             $items[] = array('name' => $item->getName(), 'id' => $item->getKey());
             ++$count;
             if ($count >= $limit) {
                 break;
             }
         }
     }
     $displayOffset += $count;
     echo JsonComponent::encode(array('status' => 'ok', 'totalResults' => $totalResults, 'solrOffset' => $solrOffset, 'displayOffset' => $displayOffset, 'items' => $items));
 }
예제 #2
0
 /**
  * Search using Lucene search text queries.
  *
  * @path /solr/search
  * @http GET
  * @param query The Lucene search query
  * @param limit (Optional) The limit of the search; defaults to 25
  * @return The list of items matching the search query
  *
  * @param array $args parameters
  * @return array
  * @throws Exception
  */
 public function searchAdvanced($args)
 {
     $apihelperComponent = MidasLoader::loadComponent('Apihelper');
     $apihelperComponent->validateParams($args, array('query'));
     $solrComponent = MidasLoader::loadComponent('Solr', 'solr');
     $authComponent = MidasLoader::loadComponent('Authentication');
     $userDao = $authComponent->getUser($args, Zend_Registry::get('userSession')->Dao);
     $limit = array_key_exists('limit', $args) ? (int) $args['limit'] : 25;
     $itemIds = array();
     try {
         $index = $solrComponent->getSolrIndex();
         UtilityComponent::beginIgnoreWarnings();
         // underlying library can generate warnings, we need to eat them
         $response = $index->search($args['query'], 0, $limit * 5, array('fl' => '*,score'));
         // extend limit to allow some room for policy filtering
         UtilityComponent::endIgnoreWarnings();
         foreach ($response->response->docs as $doc) {
             $itemIds[] = $doc->key;
         }
     } catch (Exception $e) {
         throw new Exception('Syntax error in query', -1);
     }
     /** @var ItemModel $itemModel */
     $itemModel = MidasLoader::loadModel('Item');
     $items = array();
     $count = 0;
     foreach ($itemIds as $itemId) {
         $item = $itemModel->load($itemId);
         if ($item && $itemModel->policyCheck($item, $userDao)) {
             $itemArray = $item->toArray();
             $itemInfo = array();
             $itemInfo['id'] = $itemArray['item_id'];
             $itemInfo['name'] = $itemArray['name'];
             $itemInfo['description'] = $itemArray['description'];
             $itemInfo['size'] = $itemArray['sizebytes'];
             $itemInfo['date_created'] = $itemArray['date_creation'];
             $itemInfo['date_updated'] = $itemArray['date_update'];
             $itemInfo['uuid'] = $itemArray['uuid'];
             $itemInfo['views'] = $itemArray['view'];
             $itemInfo['downloads'] = $itemArray['download'];
             $itemInfo['public'] = $itemArray['privacy_status'] == 0;
             $owningFolders = $item->getFolders();
             if (count($owningFolders) > 0) {
                 $itemInfo['folder_id'] = $owningFolders[0]->getKey();
             }
             $revisionsArray = array();
             $revisions = $item->getRevisions();
             foreach ($revisions as $revision) {
                 if (!$revision) {
                     continue;
                 }
                 $tmp = $revision->toArray();
                 $revisionsArray[] = $tmp['itemrevision_id'];
             }
             $itemInfo['revisions'] = $revisionsArray;
             // get bitstreams only from last revision
             $bitstreamArray = array();
             $headRevision = $itemModel->getLastRevision($item);
             if ($headRevision !== false) {
                 $bitstreams = $headRevision->getBitstreams();
                 foreach ($bitstreams as $b) {
                     $btmp = $b->toArray();
                     $bitstreamArray[] = $btmp['bitstream_id'];
                 }
             }
             $itemInfo['bitstreams'] = $bitstreamArray;
             $items[] = $itemInfo;
             ++$count;
             if ($count >= $limit) {
                 break;
             }
         }
     }
     return $items;
 }
예제 #3
0
 /** Add a dashboard entry on the admin dashboard for showing solr status */
 public function getAdminDashboard()
 {
     try {
         UtilityComponent::beginIgnoreWarnings();
         $index = $this->ModuleComponent->Solr->getSolrIndex();
         $index->search('metadata: foo', 0, 1);
         // run a simple test query
         UtilityComponent::endIgnoreWarnings();
         return array('Solr server accepting queries' => array(true));
     } catch (Exception $e) {
         UtilityComponent::endIgnoreWarnings();
         return array('Solr server accepting queries' => array(false));
     }
 }