コード例 #1
0
ファイル: BoolTest.php プロジェクト: richardmiller/Elastica
 /**
  * Test to resolve the following issue
  *
  * https://groups.google.com/forum/?fromgroups#!topic/elastica-php-client/zK_W_hClfvU
  */
 public function testToArrayStructure()
 {
     $boolQuery = new Elastica_Query_Bool();
     $term1 = new Elastica_Query_Term();
     $term1->setParam('interests', 84);
     $term2 = new Elastica_Query_Term();
     $term2->setParam('interests', 92);
     $boolQuery->addShould($term1)->addShould($term2);
     $jsonString = '{"bool":{"should":[{"term":{"interests":84}},{"term":{"interests":92}}]}}';
     $this->assertEquals($jsonString, json_encode($boolQuery->toArray()));
 }
コード例 #2
0
ファイル: TermTest.php プロジェクト: richardmiller/Elastica
 public function testToArray()
 {
     $query = new Elastica_Query_Term();
     $key = 'name';
     $value = 'nicolas';
     $boost = 2;
     $query->setTerm($key, $value, $boost);
     $data = $query->toArray();
     $this->assertInternalType('array', $data['term']);
     $this->assertInternalType('array', $data['term'][$key]);
     $this->assertEquals($data['term'][$key]['value'], $value);
     $this->assertEquals($data['term'][$key]['boost'], $boost);
 }
コード例 #3
0
 /**
  * Cleans index.
  *
  * @param int $storeId
  * @param int $id
  * @param string $type
  * @return mixed
  */
 public function cleanIndex($storeId = null, $id = null, $type = 'product')
 {
     $this->_prepareIndex();
     if ($this->getStatus()->indexExists($this->_index)) {
         if (null === $storeId) {
             // no store filter
             if (empty($id)) {
                 // delete ALL docs of type $type
                 return $this->getIndex($this->_index)->getType($type)->delete();
             } else {
                 // delete docs of type $type with _id in $id
                 foreach (Mage::app()->getStores() as $store) {
                     $this->cleanIndex($store->getId(), $id, $type);
                 }
             }
         } else {
             if (empty($id)) {
                 // delete ALL docs from specific store
                 $path = sprintf('%s/%s/_query', $this->_index, $type);
                 $query = new Elastica_Query_Term();
                 $query->setTerm('store_id', $storeId);
                 $response = $this->request($path, Elastica_Request::DELETE, $query->toArray());
                 return new Elastica_ResultSet($response);
             } else {
                 // delete docs from specific store with _id in $id
                 $ids = (array) $id;
                 foreach ($ids as &$id) {
                     $id .= '|' . $storeId;
                 }
                 unset($id);
                 return $this->deleteIds($ids, $this->_index, $type);
             }
         }
     }
     return $this;
 }
コード例 #4
0
ファイル: QueryTest.php プロジェクト: ro-ka/Elastica
	public function testGetQuery() {
		$query = new Elastica_Query();

		try {
			$query->getQuery();
			$this->fail('should throw exception because query does not exist');
		} catch(Elastica_Exception_Invalid $e) {
			$this->assertTrue(true);
		}


		$termQuery = new Elastica_Query_Term();
		$termQuery->setTerm('text', 'value');
		$query->setQuery($termQuery);

		$this->assertEquals($termQuery->toArray(), $query->getQuery());
	}