public function deleteByQuery($query, $args = array(), $waitLastCall = true)
{
$args['attributesToRetrieve'] = 'objectID';
$args['hitsPerPage'] = 1000;
$args['distinct'] = false;
$deletedCount = 0;
$results = $this->search($query, $args);
while ($results['nbHits'] != 0) {
$objectIDs = array();
foreach ($results['hits'] as $elt) {
array_push($objectIDs, $elt['objectID']);
}
$res = $this->deleteObjects($objectIDs);
$deletedCount += count($objectIDs);
if ($results['nbHits'] < $args['hitsPerPage'] && false === $waitLastCall) {
break;
}
$this->waitTask($res['taskID']);
$results = $this->search($query, $args);
}
return $deletedCount;
}