Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/schema-analyzers.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ $arangoClient->schema()->replaceAnalyzer('myAnalyzer', [
```

### deleteAnalyzer(string $name): bool
Delete the analyzer by its name.

```
$arangoClient->schema()->deleteAnalyzer('myAnalyzer');
```

### deleteAllAnalyzers(): bool
This method deletes all custom analyzers available on the current database.

```
$arangoClient->schema()->deleteAllAnalyzers();
```

28 changes: 28 additions & 0 deletions src/Schema/ManagesAnalyzers.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,34 @@ public function deleteAnalyzer(string $name): bool
return (bool) $this->arangoClient->request('delete', $uri);
}

/**
* Removes all custom analyzes defined for the current database.
*
* @see https://docs.arangodb.com/stable/develop/http-api/analyzers/#remove-an-analyzer
*
* @throws ArangoException
*/
public function deleteAllAnalyzers(): bool
{
$analyzers = $this->getAnalyzers();

$database = $this->arangoClient->getDatabase();

foreach ($analyzers as $analyzer) {
if (!str_starts_with($analyzer->name, "$database::")) {
continue;
}

$uri = '/_api/analyzer/' . $analyzer->name;

$this->arangoClient->request('delete', $uri);
}

return true;
}



/**
* @see https://docs.arangodb.com/stable/develop/http-api/analyzers/#list-all-analyzers
*
Expand Down
20 changes: 20 additions & 0 deletions tests/SchemaManagerAnalyzersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,23 @@
$hasAnalyzer = $this->schemaManager->hasAnalyzer($fullName);
expect($hasAnalyzer)->toBeFalse();
});

test('deleteAllAnalyzers', function () {
$initialAnalyzers = $this->schemaManager->getAnalyzers();

$this->schemaManager->createAnalyzer([
'name' => 'customAnalyzer1',
'type' => 'identity',
]);
$this->schemaManager->createAnalyzer([
'name' => 'customAnalyzer2',
'type' => 'identity',
]);

$this->schemaManager->deleteAllAnalyzers();

$endAnalyzers = $this->schemaManager->getAnalyzers();

// We already have an analyzer that is created before all tests. So, three analyzers are actually deleted.
expect(count($initialAnalyzers) - 1)->toBe(count($endAnalyzers));
});