Beispiel #1
0
 /**
  * Processes the provided Carrot2 job.
  *
  * @return returns Carrot2Result with processing results
  * @throws Carrot2Exception in case of unrecoverable errors, e.g. no connection to DCS
  */
 public function cluster(Carrot2Job $job)
 {
     $curl = curl_init($this->baseurl);
     // Prepare request parameters
     $fields = array_merge($job->getAttributes(), array('dcs.output.format' => 'XML'));
     $documents = $job->getDocuments();
     if (count($documents) > 0) {
         $fields['dcs.c2stream'] = $this->generateXml($documents);
     }
     self::addIfNotNull($fields, 'dcs.source', $job->getSource());
     self::addIfNotNull($fields, 'dcs.algorithm', $job->getAlgorithm());
     self::addIfNotNull($fields, 'query', $job->getQuery());
     // Make POST request
     curl_setopt_array($curl, array(CURLOPT_POST => true, CURLOPT_HTTPHEADER => array('Content-Type: multipart/formdata'), CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => $fields));
     $response = curl_exec($curl);
     $error = curl_errno($curl);
     if ($error !== 0) {
         throw new Carrot2Exception(curl_error($curl));
     }
     $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     if ($httpStatus >= 400) {
         throw new Carrot2Exception('HTTP error occurred, error code: ' . $httpStatus);
     }
     return $this->extractResponse($response);
 }