Skip to content

Commit 2a958df

Browse files
committed
Added the count function, that got lost during the 6.0 upgrade
1 parent fe3801c commit 2a958df

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

Service/IndexService.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,35 @@ private function executeSearch(Search $search): array
308308

309309
public function getIndexDocumentCount(): int
310310
{
311-
$body = [
312-
'index' => $this->getIndexName(),
313-
'body' => [],
314-
];
311+
return $this->count();
312+
}
313+
314+
/**
315+
* Counts documents by given search.
316+
*
317+
* @param Search|null $search
318+
* @param array $params
319+
* @param bool $returnRaw If set true returns raw response gotten from client.
320+
*
321+
* @return int|array
322+
*/
323+
public function count(Search $search = null, array $params = [], $returnRaw = false)
324+
{
325+
$body = array_merge(
326+
[
327+
'index' => $this->getIndexName(),
328+
'body' => $search !== null ? $search->toArray() : [],
329+
],
330+
$params
331+
);
315332

316333
$results = $this->getClient()->count($body);
317334

318-
return $results['count'];
335+
if ($returnRaw) {
336+
return $results;
337+
} else {
338+
return $results['count'];
339+
}
319340
}
320341

321342
public function remove($id, $routing = null)

0 commit comments

Comments
 (0)