Skip to content

Commit b97023f

Browse files
committed
Add Schema::dropSearchIndex()
1 parent aae9170 commit b97023f

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
@@ -539,6 +539,14 @@ public function testSearchIndex(): void
539539
self::assertSame('search', $index['type']);
540540
self::assertFalse($index['latestDefinition']['mappings']['dynamic']);
541541
self::assertSame('lucene.whitespace', $index['latestDefinition']['mappings']['fields']['foo']['analyzer']);
542+
543+
// Drop the index using default name
544+
Schema::table('newcollection', function (Blueprint $collection) {
545+
$collection->dropSearchIndex();
546+
});
547+
548+
$index = $this->getSearchIndex('newcollection', 'default');
549+
self::assertNull($index);
542550
}
543551

544552
public function testVectorSearchIndex()
@@ -559,6 +567,14 @@ public function testVectorSearchIndex()
559567
self::assertSame('vector', $index['name']);
560568
self::assertSame('vectorSearch', $index['type']);
561569
self::assertSame('vector', $index['latestDefinition']['fields'][0]['type']);
570+
571+
// Drop the index
572+
Schema::table('newcollection', function (Blueprint $collection) {
573+
$collection->dropSearchIndex('vector');
574+
});
575+
576+
$index = $this->getSearchIndex('newcollection', 'vector');
577+
self::assertNull($index);
562578
}
563579

564580
protected function assertIndexExists(string $collection, string $name): IndexInfo

0 commit comments

Comments
 (0)