Skip to content

Commit dd097d8

Browse files
author
Ethan Hann
committed
Add physical delete document (DD) option
1 parent c5c90bf commit dd097d8

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/Index.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,16 @@ public function info()
140140

141141
/**
142142
* @param $id
143+
* @param bool $deleteDocument
143144
* @return bool
144145
*/
145-
public function delete($id)
146+
public function delete($id, $deleteDocument = false)
146147
{
147-
return boolval($this->rawCommand('FT.DEL', [$this->getIndexName(), $id]));
148+
$arguments = [$this->getIndexName(), $id];
149+
if ($deleteDocument) {
150+
$arguments[] = 'DD';
151+
}
152+
return boolval($this->rawCommand('FT.DEL', $arguments));
148153
}
149154

150155
/**

src/IndexInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface IndexInterface extends BuilderInterface
1111
public function create();
1212
public function drop();
1313
public function info();
14-
public function delete($id);
14+
public function delete($id, $deleteDocument = false);
1515
public function makeDocument($id = null): DocumentInterface;
1616
public function makeAggregateBuilder(): AggregateBuilderInterface;
1717
public function getRedisClient(): RediSearchRedisClient;

tests/RediSearch/IndexTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ public function testShouldDeleteDocumentById()
9494
$this->assertEmpty($this->subject->search('My New Book')->getDocuments());
9595
}
9696

97+
public function testShouldPhysicallyDeleteDocumentById()
98+
{
99+
$this->subject->create();
100+
$expectedId = 'fio4oihfohsdfl';
101+
$document = $this->subject->makeDocument($expectedId);
102+
$document->title->setValue('My New Book');
103+
$document->author->setValue('Jack');
104+
$document->price->setValue(123);
105+
$document->stock->setValue(1123);
106+
$this->subject->add($document);
107+
108+
$result = $this->subject->delete($expectedId, true);
109+
110+
$this->assertTrue($result);
111+
$this->assertEmpty($this->subject->search('My New Book')->getDocuments());
112+
}
113+
97114
public function testCreateIndexWithSortableFields()
98115
{
99116
$indexName = 'IndexWithSortableFieldsTest';

0 commit comments

Comments
 (0)