Skip to content

Commit b83e184

Browse files
authored
Merge pull request #118 from apisearch-io/feature/added-delete-items-by-query
Added delete-items-by-query method in repository
2 parents 2de4e30 + 4cb9011 commit b83e184

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

Repository/HttpRepository.php

+24
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,30 @@ public function updateItems(
131131
self::throwTransportableExceptionIfNeeded($response);
132132
}
133133

134+
/**
135+
* Delete items by query
136+
*
137+
* @param Query $query
138+
*/
139+
public function deleteItemsByQuery(Query $query)
140+
{
141+
$response = $this
142+
->httpClient
143+
->get(
144+
sprintf(
145+
'/%s/indices/%s/items/by-query',
146+
$this->getAppUUID()->composeUUID(),
147+
$this->getIndexUUID()->composeUUID()
148+
),
149+
'delete',
150+
[],
151+
$query->toArray(),
152+
Http::getApisearchHeaders($this)
153+
);
154+
155+
self::throwTransportableExceptionIfNeeded($response);
156+
}
157+
134158
/**
135159
* Search across the index types.
136160
*

Repository/InMemoryRepository.php

+10
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ public function updateItems(
9797
throw new LogicException('Update endpoint cannot be tested against memory implementation, but only in final implementation');
9898
}
9999

100+
/**
101+
* Delete items by query
102+
*
103+
* @param Query $query
104+
*/
105+
public function deleteItemsByQuery(Query $query)
106+
{
107+
throw new LogicException('Update endpoint cannot be tested against memory implementation, but only in final implementation');
108+
}
109+
100110
/**
101111
* Get items.
102112
*

Repository/MockRepository.php

+10
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ public function updateItems(
7272
$this->throwMockException();
7373
}
7474

75+
/**
76+
* Delete items by query
77+
*
78+
* @param Query $query
79+
*/
80+
public function deleteItemsByQuery(Query $query)
81+
{
82+
$this->throwMockException();
83+
}
84+
7585
/**
7686
* Throw exception.
7787
*

Repository/Repository.php

+7
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,11 @@ abstract public function updateItems(
199199
Query $query,
200200
Changes $changes
201201
);
202+
203+
/**
204+
* Delete items by query
205+
*
206+
* @param Query $query
207+
*/
208+
abstract public function deleteItemsByQuery(Query $query);
202209
}

Repository/TransformableRepository.php

+12
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@ public function updateItems(
184184
);
185185
}
186186

187+
/**
188+
* Delete items by query
189+
*
190+
* @param Query $query
191+
*/
192+
public function deleteItemsByQuery(Query $query)
193+
{
194+
$this
195+
->repository
196+
->deleteItemsByQuery($query);
197+
}
198+
187199
/**
188200
* Generate item document by a simple object.
189201
*

0 commit comments

Comments
 (0)