/** * index() - add or update a document in the index * * Expects either a string file, string in-memory document, * or a Doc object. * * @param string_or_object $doc * @param string $uri (optional) * @param string $content_type (optional) * @return HTTPResponse $resp */ public function index($doc, $uri = null, $content_type = null) { $buf = null; $mtime = time(); if (!is_object($doc) && file_exists($doc)) { $buf = file_get_contents($doc); $mtime = filemtime($doc); if ($uri == null) { $uri = $doc; } } elseif (!is_object($doc)) { $buf = $doc; if ($uri == null) { throw new \Exception("uri required"); } } elseif (is_object($doc) && is_a($doc, '\\Dezi\\Doc')) { $buf = $doc->as_string(); $mtime = $doc->mtime; if ($uri == null) { $uri = $doc->uri; } if ($content_type == null) { $content_type = $doc->mime_type; } } else { throw new \Exception("doc must be a file, in-memory buffer, or \\Dezi\\Doc object"); } if ($content_type == null) { $content_type = Doc::get_mime_type($uri); } //error_log("content_type=$content_type"); $pest = $this->_new_user_agent($this->index_uri, 'Pest'); $resp = $pest->post("/{$uri}", $buf, array('Content-Type: ' . $content_type, 'X-SOS-Last-Modified: ' . $mtime)); $http_resp = new HTTPResponse(); $http_resp->status = $pest->lastStatus(); $http_resp->content = $resp; return $http_resp; }