Skip to content

Commit c867aef

Browse files
mnoconadriendupuis
andauthored
Described disabling counting the results (#3180)
* Described disabling counting the results * Fixed link * Update docs/search/search_api.md Co-authored-by: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> --------- Co-authored-by: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com>
1 parent 4536a60 commit c867aef

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php declare(strict_types=1);
2+
3+
use Ibexa\Contracts\Core\Repository\Values\Content\LocationQuery;
4+
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
5+
6+
/** @var \Ibexa\Contracts\Core\Repository\SearchService $searchService */
7+
8+
// For location searches
9+
$locationQuery = new LocationQuery();
10+
$locationQuery->performCount = false;
11+
12+
$locationResult = $searchService->findLocations($locationQuery);
13+
14+
// For content searches
15+
$contentQuery = new Query();
16+
$contentQuery->performCount = false;
17+
18+
$contentResult = $searchService->findContent($contentQuery);

docs/search/search_api.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ $output->writeln($result->getName());
6161
$query->limit = 100;
6262
```
6363

64+
#### Disable result count
65+
66+
By default, a search query also counts all matching results.
67+
If you don't need the total count, set `performCount` to `false` on [`Query`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Query.html) or [`LocationQuery`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-LocationQuery.html) to improve performance, especially for large result sets.
68+
69+
``` php
70+
[[= include_code('code_samples/api/public_php_api/src/perform_count.php', 8, 10) =]]
71+
72+
[[= include_code('code_samples/api/public_php_api/src/perform_count.php', 14, 16) =]]
73+
```
74+
75+
When `performCount` is set to `false`, `$result->totalCount` is `null`.
76+
6477
#### Search with `query` and `filter`
6578

6679
You can use two properties of the `Query` object to search for content: `query` and `filter`.

0 commit comments

Comments
 (0)