FOSElasticaBundle/Reseter.php

36 lines
662 B
PHP
Raw Normal View History

2011-04-13 00:14:00 +02:00
<?php
namespace FOQ\ElasticaBundle;
use Elastica_Exception_Response;
2011-04-13 00:14:00 +02:00
/**
* Deletes and recreates indexes
**/
class Reseter
{
protected $indexManager;
public function __construct(IndexManager $indexManager)
{
$this->indexManager = $indexManager;
}
/**
* Resets all indexes
*
* @return null
**/
public function reset()
{
foreach ($this->indexManager->getAllIndexes() as $index) {
try {
$index->delete();
} catch (Elastica_Exception_Response $e) {
// The index does not exist
}
2011-04-13 00:14:00 +02:00
$index->create();
}
}
}