/** *This is all horribly terible and will be ripped out as soon as possible. * * Basically, This class stores an intermediate Command that maintains state across * chained requests, which allows updates (scripts, params, etc) to affect it. * * The command is finalized when a new document is added, or the request is executed. * Finalization means collapsing the doc field data into a param, as well as updating * the action/suffix as necessary. */ private function finalizeCurrentCommand() { if ($this->batch instanceof BatchCommand && $this->currentCommand !== null) { if (isset($this->params['update']) && $this->params['update'] === true) { $this->currentCommand->action('post')->suffix('_update'); if ($this->params['doc'] !== null) { $data["doc"] = $this->params['doc']; } if ($this->params['updateScript'] !== null) { $data["script"] = $this->params['updateScript']; } if ($this->params['updateParams'] !== null) { $data["params"] = $this->params['updateParams']; } if ($this->params['updateUpsert'] !== null) { $data["upsert"] = $this->params['updateUpsert']; } $this->currentCommand->data($data); } else { $this->currentCommand->data($this->params['doc']); } $this->batch->addCommand($this->currentCommand); $this->params['update'] = false; } $this->currentCommand = new Command(); }
/** * Pregenerate 2000 docs to insert, just as a demonstration * This could easily be opening a filestream, etc */ public function __construct() { for ($i = 0; $i < 2000; $i++) { $tDoc = new Sherlock\requests\Command(); $tDoc->action('post')->index('testindexing')->type('tweet')->data('{"field":"test"}'); $this->commands[] = $tDoc; } }