Example #1
0
 /**
  * Deletes a single item from the index.
  *
  * @param string $key The unique key of the item to delete.
  */
 protected function deleteItem($key)
 {
     $solr = \JSolr\Index\Factory::getService();
     $solr->deleteById($key);
     $solr->commit();
 }
Example #2
0
 /**
  * A convenience event for adding a record to the index.
  *
  * Use this event when the plugin is known but the context is not.
  *
  * @param int $id The id of the record being added.
  */
 public function onItemAdd($id)
 {
     $commitWithin = $this->params->get('component.commitWithin', '1000');
     $endpoint = $this->params->get('rest_url') . '/items/%s.json';
     try {
         $url = new JUri(JText::sprintf($endpoint, $id));
         $http = JHttpFactory::getHttp();
         $response = $http->get((string) $url);
         if ((int) $response->code !== 200) {
             throw new Exception($response->body, $response->code);
         }
         $item = json_decode($response->body);
         // DSpace is incapable of exposing item permissions in a clean acl
         // manner. Query src Solr for this information.
         $temp = $this->getItems(0, 1, "search.resourceid:" . $id);
         $item->access = $this->setAccess($temp);
         $document = $this->prepare($item);
         $solr = \JSolr\Index\Factory::getService();
         $solr->addDocuments($document, false, true, true, $commitWithin);
     } catch (Exception $e) {
         JLog::add($e->getMessage(), JLog::ERROR, 'jsolrcrawler');
     }
 }
Example #3
0
 protected function purge()
 {
     $plugin = $this->_getPlugin();
     if ($plugin) {
         $this->_fireEvent('onPurge', array(get_class($this), $this->_isVerbose()), $plugin);
     } else {
         $solr = \JSolr\Index\Factory::getService();
         if ($solr->ping()) {
             $this->out('purging all items from index...');
             // more efficient than calling each plugin's onPurge.
             $solr->deleteByQuery("*:*");
             $solr->commit();
             $this->out('purging index completed.');
         }
     }
 }