Exemplo n.º 1
0
	/**
	 * Adds the given document to the search index
	 *
	 * @param Elastica_Document $doc Document with data
	 * @return Elastica_Response
	 */
	public function addDocument(Elastica_Document $doc) {

		$path = $doc->getId();

		$query = array();

		if ($doc->getVersion() > 0) {
			$query['version'] = $doc->getVersion();
		}

		if (!is_null($doc->getParent())) {
			$query['parent'] = $doc->getParent();
		}

		if ($doc->getOpType()) {
			$query['op_type'] = $doc->getOpType();
		}

		if ($doc->getPercolate()) {
			$query['percolate'] = $doc->getPercolate();
		}

		$type = Elastica_Request::PUT;

		// If id is empty, POST has to be used to automatically create id
		if (empty($path)) {
			$type = Elastica_Request::POST;
		}

		return $this->request($path, $type, $doc->getData(), $query);
	}
Exemplo n.º 2
0
 /**
  * Adds the given document to the search index
  *
  * @param Elastica_Document $doc Document with data
  * @return Elastica_Response
  */
 public function addDocument(Elastica_Document $doc)
 {
     $path = $doc->getId();
     if ($doc->getVersion() > 0) {
         $path .= '?version=' . $doc->getVersion();
     }
     return $this->request($path, Elastica_Request::PUT, $doc->getData());
 }
Exemplo n.º 3
0
 /**
  * Adds the given document to the search index
  *
  * @param Elastica_Document $doc Document with data
  * @return Elastica_Response
  */
 public function addDocument(Elastica_Document $doc)
 {
     $path = $doc->getId();
     $query = array();
     if ($doc->getVersion() > 0) {
         $query['version'] = $doc->getVersion();
     }
     if ($doc->getParent()) {
         $query['parent'] = $doc->getParent();
     }
     if (count($query) > 0) {
         $path .= '?' . http_build_query($query);
     }
     $type = Elastica_Request::PUT;
     // If id is empty, POST has to be used to automatically create id
     if (empty($path)) {
         $type = Elastica_Request::POST;
     }
     return $this->request($path, $type, $doc->getData());
 }