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); }
/** * 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; }
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()); }