Beispiel #1
0
 /**
  * @param SavableModelInterface $model
  * @throws CouldNotPurgeException
  */
 public function purge(SavableModelInterface $model)
 {
     $update = $this->solrClient->createUpdate();
     $update->addDeleteById($model->getId());
     $update->addCommit();
     $result = $this->solrClient->update($update);
     if ($result->getStatus() != 0) {
         throw new CouldNotPurgeException('Model could not purge: ' . $result->getResponse()->getStatusMessage());
     }
 }
Beispiel #2
0
 /**
  * Implements Search::Framework::SearchEngineAbstract::delete().
  *
  * @return \Solarium\QueryType\Update\Result
  */
 public function delete()
 {
     $update = $this->_client->createUpdate();
     $update->addDeleteQuery('*:*');
     $update->addCommit();
     return $this->_client->update($update);
 }
Beispiel #3
0
 /**
  * {@inheritDoc}
  */
 public function flush()
 {
     if (!is_object($this->update)) {
         return;
     }
     $this->client->update($this->update);
     $this->update = null;
 }
 /**
  * Optimize the Solr index.
  *
  * @return bool - True on success
  */
 public function optimize()
 {
     if (!$this->_working) {
         return false;
     }
     // get an update query instance
     $update = $this->_client->createUpdate();
     $update->addOptimize();
     $solariumResult = $this->_client->update($update, 'update');
     return $this->processResult($solariumResult, 'optimize');
 }
 public function delete($id, $core)
 {
     try {
         $this->_config['endpoint']['localhost']['path'] = '/solr/' . $core . '/';
         // create a client instance
         $client = new Client($this->_config);
         // get an update query instance
         $update = $client->createUpdate();
         // add the delete id and a commit command to the update query
         $update->addDeleteById($id);
         $update->addCommit();
         // this executes the query and returns the result
         $result = $client->update($update);
         if ($result->getStatus()) {
             throw new Exception('Invalid result returned from solr.');
         }
     } catch (Exception $e) {
         $this->_log($e);
     }
 }
Beispiel #6
0
 /**
  * @param QueryInterface $query
  */
 private function applyOnAllCores(QueryInterface $query)
 {
     foreach ($this->solariumClient->getEndpoints() as $endpointName => $endpoint) {
         $this->solariumClient->update($query, $endpointName);
     }
 }
 /**
  * Add multiple documents to the data store.
  *
  * @param \Solarium\QueryType\Update\Query\Query $updateQuery
  * @param array $documents
  */
 protected function addDocuments(Query $updateQuery, array $documents)
 {
     $updateQuery->addDocuments($documents);
     $this->client->update($updateQuery);
 }
 /**
  * {@inheritdoc}
  */
 public function deleteAllIndexItems(IndexInterface $index = NULL)
 {
     $this->connect();
     if ($index) {
         // Since the index ID we use for indexing can contain arbitrary
         // prefixes, we have to escape it for use in the query.
         $index_id = $this->getQueryHelper()->escapePhrase($index->id());
         $index_id = $this->getIndexId($index_id);
         $query = '(index_id:' . $index_id . ')';
         $site_hash = $this->getQueryHelper()->escapePhrase(SearchApiSolrUtility::getSiteHash());
         $query .= ' AND (hash:' . $site_hash . ')';
         $this->getUpdateQuery()->addDeleteQuery($query);
     } else {
         $this->getUpdateQuery()->addDeleteQuery('*:*');
     }
     // Do a commitWithin since that is automatically a softCommit with Solr 4
     // and a delayed hard commit with Solr 3.4+.
     // We wait 1 second after the request arrived for solr to parse the commit.
     // This allows us to return to Drupal and let Solr handle what it
     // needs to handle
     // @see http://wiki.apache.org/solr/NearRealtimeSearch
     /** @var \Solarium\Plugin\CustomizeRequest\CustomizeRequest $customizer */
     $customizer = $this->solr->getPlugin('customizerequest');
     $customizer->createCustomization('id')->setType('param')->setName('commitWithin')->setValue('1000');
     $this->solr->update($this->getUpdateQuery());
 }