private function importFile(Client $client, $core, SplFileInfo $source, $output) { $output->writeln("Importing data from: <info>{$source}</info>"); $fp = fopen($source, 'r'); $path = "{$core}/update?" . http_build_query(['commit' => 'true', 'wt' => 'json']); $headers = ['Content-Type' => 'application/json']; $response = $client->post($path, $fp, $headers); $contents = $response->getBody()->getContents(); $reply = Json::decode($contents); if ($reply->responseHeader->status != 0) { throw new \Exception("Solr returned an error."); } $time = $reply->responseHeader->QTime; $output->writeln("Time taken: <comment>{$time} ms</comment>\n"); }
/** * Pings the server to check it's there. * * @return array Decoded response from the Solr server. */ public function ping() { $path = implode('/', [$this->name, $this->pingHandler]); $path = "{$path}?wt=json"; $response = $this->client->get($path); $contents = $response->getBody()->getContents(); return Json::decode($contents, true); }
public function connect() { $this->solr_client = Client::factory($this->dsn, $this->options); if (!$this->solr_client) { $this->error_msg = 'Could not connect to Solr'; $this->error = true; } return $this->error; }
public function testFactory() { $url = "www.google.com"; $timeout = 666; $defaults = ['timeout' => $timeout]; $client = Client::factory($url, $defaults); $guzzle = $client->getGuzzleClient(); $this->assertSame($url, strval($guzzle->getConfig('base_uri'))); $this->assertSame($timeout, $guzzle->getConfig('timeout')); }