Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions code_samples/api/public_php_api/src/perform_count.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

use Ibexa\Contracts\Core\Repository\Values\Content\LocationQuery;
use Ibexa\Contracts\Core\Repository\Values\Content\Query;

/** @var \Ibexa\Contracts\Core\Repository\SearchService $searchService */

// For location searches
$locationQuery = new LocationQuery();
$locationQuery->performCount = false;

$locationResult = $searchService->findLocations($locationQuery);

// For content searches
$contentQuery = new Query();
$contentQuery->performCount = false;

$contentResult = $searchService->findContent($contentQuery);
13 changes: 13 additions & 0 deletions docs/search/search_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ $output->writeln($result->getName());
$query->limit = 100;
```

#### Disable result count

By default, a search query also counts all matching results.
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.

``` php
[[= include_code('code_samples/api/public_php_api/src/perform_count.php', 8, 10) =]]

[[= include_code('code_samples/api/public_php_api/src/perform_count.php', 14, 16) =]]
```

When `performCount` is set to `false`, `$result->totalCount` is `null`.

#### Search with `query` and `filter`

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