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
 /**
  * Match a document to percolator queries
  *
  * @param  Elastica_Document                             $doc
  * @param  string|Elastica_Query|Elastica_Query_Abstract $query Not implemented yet
  * @return Elastica_Response
  */
 public function matchDoc(Elastica_Document $doc, $query = null)
 {
     $path = $this->_index->getName() . '/type/_percolate';
     $data = array('doc' => $doc->getData());
     $response = $this->getIndex()->getClient()->request($path, Elastica_Request::GET, $data);
     $data = $response->getData();
     return $data['matches'];
 }
Exemplo n.º 3
0
	public function testAdd() {
		$doc = new Elastica_Document();
		$returnValue = $doc->add('key', 'value');
		$data = $doc->getData();
		$this->assertArrayHasKey('key', $data);
		$this->assertEquals('value', $data['key']);
		$this->assertInstanceOf('Elastica_Document', $returnValue);
	}
Exemplo n.º 4
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.º 5
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());
 }