/** * The document to index * * @param \string|\array $value * @param null $id * @param bool|null $update * * @throws \Sherlock\common\exceptions\RuntimeException * @return IndexDocumentRequest */ public function document($value, $id = null, $update = false) { if (!$this->batch instanceof BatchCommand) { throw new exceptions\RuntimeException("Cannot add a new document to an external BatchCommandInterface"); } $this->finalizeCurrentCommand(); if (is_array($value)) { $this->params['doc'] = $value; } elseif (is_string($value)) { $this->params['doc'] = json_decode($value, true); } if ($id !== null) { $this->currentCommand->id($id)->action('put'); $this->params['update'] = $update; } else { $this->currentCommand->action('post'); $this->params['update'] = false; } return $this; }
/** * The document to delete * * @param null $id * * @throws \Sherlock\common\exceptions\RuntimeException * @return DeleteDocumentRequest */ public function document($id) { if (!$this->batch instanceof BatchCommand) { throw new exceptions\RuntimeException("Cannot delete a document from an external BatchCommandInterface"); } $command = new Command(); $command->id($id)->action('delete'); //Only doing this because typehinting is wonky without it... if ($this->batch instanceof BatchCommand) { $this->batch->addCommand($command); } return $this; }