Skip to content

Commit c8f9bd5

Browse files
committed
Add Schema::dropSearchIndex()
1 parent 6cb3838 commit c8f9bd5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Schema/Blueprint.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,16 @@ public function vectorSearchIndex(array $definition, string $name = 'default'):
339339
return $this;
340340
}
341341

342+
/**
343+
* Drop an Atlas Search or Vector Search index
344+
*/
345+
public function dropSearchIndex(string $name = 'default'): static
346+
{
347+
$this->collection->dropSearchIndex($name);
348+
349+
return $this;
350+
}
351+
342352
/**
343353
* Allow fluent columns.
344354
*

tests/SchemaTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,14 @@ public function testSearchIndex(): void
551551
self::assertSame('search', $index['type']);
552552
self::assertFalse($index['latestDefinition']['mappings']['dynamic']);
553553
self::assertSame('lucene.whitespace', $index['latestDefinition']['mappings']['fields']['foo']['analyzer']);
554+
555+
// Drop the index using default name
556+
Schema::table('newcollection', function (Blueprint $collection) {
557+
$collection->dropSearchIndex();
558+
});
559+
560+
$index = $this->getSearchIndex('newcollection', 'default');
561+
self::assertNull($index);
554562
}
555563

556564
public function testVectorSearchIndex()
@@ -571,6 +579,14 @@ public function testVectorSearchIndex()
571579
self::assertSame('vector', $index['name']);
572580
self::assertSame('vectorSearch', $index['type']);
573581
self::assertSame('vector', $index['latestDefinition']['fields'][0]['type']);
582+
583+
// Drop the index
584+
Schema::table('newcollection', function (Blueprint $collection) {
585+
$collection->dropSearchIndex('vector');
586+
});
587+
588+
$index = $this->getSearchIndex('newcollection', 'vector');
589+
self::assertNull($index);
574590
}
575591

576592
protected function getIndex(string $collection, string $name)

0 commit comments

Comments
 (0)