本文整理汇总了PHP中Elastica\Type::deleteById方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::deleteById方法的具体用法?PHP Type::deleteById怎么用?PHP Type::deleteById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Type
的用法示例。
在下文中一共展示了Type::deleteById方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cleanElasticSearchIndex
/**
* remove the eav deleted products from elasticsearch index
*
* @param array $productIds
*/
public function cleanElasticSearchIndex(array $productIds)
{
foreach ($productIds as $productId) {
try {
$this->_type->deleteById($productId);
} catch (Exception $e) {
//continue if $productId not found
//TODO Logging
continue;
}
}
}
示例2: removeIndexById
/**
* @param integer $id
* @param Type $type
*/
public function removeIndexById($id, Type $type)
{
try {
$type->deleteById($id);
} catch (\InvalidArgumentException $e) {
} catch (NotFoundException $e) {
}
}
示例3: testOptimize
/**
* @group functional
*/
public function testOptimize()
{
$index = $this->_createIndex();
$type = new Type($index, 'optimize');
$docs = array();
$docs[] = new Document(1, array('foo' => 'bar'));
$docs[] = new Document(2, array('foo' => 'bar'));
$type->addDocuments($docs);
$index->refresh();
$stats = $index->getStats()->getData();
$this->assertEquals(0, $stats['_all']['primaries']['docs']['deleted']);
$type->deleteById(1);
$index->refresh();
$stats = $index->getStats()->getData();
$this->assertEquals(1, $stats['_all']['primaries']['docs']['deleted']);
$index->optimize(array('max_num_segments' => 1));
$stats = $index->getStats()->getData();
$this->assertEquals(0, $stats['_all']['primaries']['docs']['deleted']);
}
示例4: testDeleteById
/**
* @group functional
*/
public function testDeleteById()
{
$index = $this->_createIndex();
$type = new Type($index, 'user');
// Adds hans, john and rolf to the index
$docs = array(new Document(1, array('username' => 'hans', 'test' => array('2', '3', '5'))), new Document(2, array('username' => 'john', 'test' => array('1', '3', '6'))), new Document(3, array('username' => 'rolf', 'test' => array('2', '3', '7'))), new Document('foo/bar', array('username' => 'georg', 'test' => array('4', '2', '5'))));
$type->addDocuments($docs);
$index->refresh();
// sanity check for rolf
$resultSet = $type->search('rolf');
$this->assertEquals(1, $resultSet->count());
$data = $resultSet->current()->getData();
$this->assertEquals('rolf', $data['username']);
// delete rolf
$type->deleteById(3);
$index->refresh();
// rolf should no longer be there
$resultSet = $type->search('rolf');
$this->assertEquals(0, $resultSet->count());
// sanity check for id with slash
$resultSet = $type->search('georg');
$this->assertEquals(1, $resultSet->count());
// delete georg
$type->deleteById('foo/bar');
$index->refresh();
// georg should no longer be there
$resultSet = $type->search('georg');
$this->assertEquals(0, $resultSet->count());
// it should not be possible to delete the entire type with this method
try {
$type->deleteById('');
$this->fail('Delete with empty string id should fail');
} catch (\InvalidArgumentException $e) {
$this->assertTrue(true);
}
try {
$type->deleteById(' ');
$this->fail('Delete with one space string id should fail');
} catch (\InvalidArgumentException $e) {
$this->assertTrue(true);
}
try {
$type->deleteById(null);
$this->fail('Delete with null id should fail');
} catch (\InvalidArgumentException $e) {
$this->assertTrue(true);
}
try {
$type->deleteById(array());
$this->fail('Delete with empty array id should fail');
} catch (\InvalidArgumentException $e) {
$this->assertTrue(true);
}
try {
$type->deleteById('*');
$this->fail('Delete request should fail because of invalid id: *');
} catch (NotFoundException $e) {
$this->assertTrue(true);
}
try {
$type->deleteById('*:*');
$this->fail('Delete request should fail because document with id *.* does not exist');
} catch (NotFoundException $e) {
$this->assertTrue(true);
}
try {
$type->deleteById('!');
$this->fail('Delete request should fail because document with id ! does not exist');
} catch (NotFoundException $e) {
$this->assertTrue(true);
}
$index->refresh();
// rolf should no longer be there
$resultSet = $type->search('john');
$this->assertEquals(1, $resultSet->count());
}
示例5: doDeleteReturnsFalseWhenNotFound
/**
* @test
*/
public function doDeleteReturnsFalseWhenNotFound()
{
$id = 1;
$this->type->deleteById($this->getCacheId($id))->shouldBeCalled()->willThrow('\\Elastica\\Exception\\NotFoundException');
self::assertFalse($this->cache->delete($id));
}
示例6: removeHotel
/**
* @param Hotel $hotel
*
* @return $this
*/
public function removeHotel($hotel)
{
$this->hotelType->deleteById($hotel->getId());
}