File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -140,11 +140,16 @@ public function info()
140
140
141
141
/**
142
142
* @param $id
143
+ * @param bool $deleteDocument
143
144
* @return bool
144
145
*/
145
- public function delete ($ id )
146
+ public function delete ($ id, $ deleteDocument = false )
146
147
{
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 ));
148
153
}
149
154
150
155
/**
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ interface IndexInterface extends BuilderInterface
11
11
public function create ();
12
12
public function drop ();
13
13
public function info ();
14
- public function delete ($ id );
14
+ public function delete ($ id, $ deleteDocument = false );
15
15
public function makeDocument ($ id = null ): DocumentInterface ;
16
16
public function makeAggregateBuilder (): AggregateBuilderInterface ;
17
17
public function getRedisClient (): RediSearchRedisClient ;
Original file line number Diff line number Diff line change @@ -94,6 +94,23 @@ public function testShouldDeleteDocumentById()
94
94
$ this ->assertEmpty ($ this ->subject ->search ('My New Book ' )->getDocuments ());
95
95
}
96
96
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
+
97
114
public function testCreateIndexWithSortableFields ()
98
115
{
99
116
$ indexName = 'IndexWithSortableFieldsTest ' ;
You can’t perform that action at this time.
0 commit comments