Skip to content

Commit

Permalink
PHPORM-283 Add Schema::dropSearchIndex() (#3235)
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN authored Jan 3, 2025
1 parent 3960aeb commit 223a9f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,16 @@ public function vectorSearchIndex(array $definition, string $name = 'default'):
return $this;
}

/**
* Drop an Atlas Search or Vector Search index
*/
public function dropSearchIndex(string $name): static
{
$this->collection->dropSearchIndex($name);

return $this;
}

/**
* Allow fluent columns.
*
Expand Down
15 changes: 15 additions & 0 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,13 @@ public function testSearchIndex(): void
self::assertSame('search', $index['type']);
self::assertFalse($index['latestDefinition']['mappings']['dynamic']);
self::assertSame('lucene.whitespace', $index['latestDefinition']['mappings']['fields']['foo']['analyzer']);

Schema::table('newcollection', function (Blueprint $collection) {
$collection->dropSearchIndex('default');
});

$index = $this->getSearchIndex('newcollection', 'default');
self::assertNull($index);
}

public function testVectorSearchIndex()
Expand All @@ -559,6 +566,14 @@ public function testVectorSearchIndex()
self::assertSame('vector', $index['name']);
self::assertSame('vectorSearch', $index['type']);
self::assertSame('vector', $index['latestDefinition']['fields'][0]['type']);

// Drop the index
Schema::table('newcollection', function (Blueprint $collection) {
$collection->dropSearchIndex('vector');
});

$index = $this->getSearchIndex('newcollection', 'vector');
self::assertNull($index);
}

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

0 comments on commit 223a9f7

Please sign in to comment.