diff --git a/code_samples/search/content/taxonomy_no_entries_criterion.php b/code_samples/search/content/taxonomy_no_entries_criterion.php new file mode 100644 index 0000000000..048006d41c --- /dev/null +++ b/code_samples/search/content/taxonomy_no_entries_criterion.php @@ -0,0 +1,19 @@ +query = new LogicalAnd( + [ + new TaxonomyNoEntries('tags'), + new ContentTypeIdentifier('article'), + ] +); + +/** @var \Ibexa\Contracts\Core\Repository\SearchService $searchService */ +$results = $searchService->findContent($query); diff --git a/code_samples/search/content/taxonomy_subtree_criterion.php b/code_samples/search/content/taxonomy_subtree_criterion.php new file mode 100644 index 0000000000..c13f94ed70 --- /dev/null +++ b/code_samples/search/content/taxonomy_subtree_criterion.php @@ -0,0 +1,19 @@ +query = new LogicalAnd( + [ + new TaxonomySubtree(42), + new ContentTypeIdentifier('article'), + ] +); + +/** @var \Ibexa\Contracts\Core\Repository\SearchService $searchService */ +$results = $searchService->findContent($query); diff --git a/docs/content_management/taxonomy/taxonomy_api.md b/docs/content_management/taxonomy/taxonomy_api.md index 3a46b2322f..49a992e859 100644 --- a/docs/content_management/taxonomy/taxonomy_api.md +++ b/docs/content_management/taxonomy/taxonomy_api.md @@ -71,3 +71,16 @@ and a `position` parameter, which is either `TaxonomyServiceInterface::MOVE_POSI Taxonomy entry management functions triggers events you can listen to. For more information, see [Taxonomy events](taxonomy_events.md). + +## Search + +You can search for content based on its taxonomy entry assignments by using the standard +[`SearchService`](search_api.md) with taxonomy-specific Search Criteria: + +| Criterion | Description | +|---|---| +| [TaxonomyEntryId](taxonomy_entry_id.md) | Find content assigned to a specific taxonomy entry | +| [TaxonomyNoEntries](taxonomy_no_entries.md) | Find content that has no entries assigned from a given taxonomy | +| [TaxonomySubtree](taxonomy_subtree.md) | Find content assigned to a taxonomy entry or any of its descendants | + +You can also use the [TaxonomyEntryId Aggregation](taxonomyentryid_aggregation.md) to count content items per taxonomy entry. diff --git a/docs/search/criteria_reference/isfieldempty_criterion.md b/docs/search/criteria_reference/isfieldempty_criterion.md index 97341ec019..8b7efaaec1 100644 --- a/docs/search/criteria_reference/isfieldempty_criterion.md +++ b/docs/search/criteria_reference/isfieldempty_criterion.md @@ -18,6 +18,9 @@ The `IsFieldEmpty` Criterion isn't available in [Repository filtering](search_ap The Richtext field type (`ezrichtext`) isn't searchable in the Legacy search engine. +The `IsFieldEmpty` criterion doesn't work for [Taxonomy entry assignment](taxonomyentryassignmentfield.md) fields. +For this use case, use [`TaxonomyNoEntries`](taxonomy_no_entries.md) instead. + ## Example ### PHP diff --git a/docs/search/criteria_reference/search_criteria_reference.md b/docs/search/criteria_reference/search_criteria_reference.md index 28c256aef2..2e73e8724c 100644 --- a/docs/search/criteria_reference/search_criteria_reference.md +++ b/docs/search/criteria_reference/search_criteria_reference.md @@ -68,6 +68,8 @@ Due to this storage limitation, searching content using the Country field type o | [Sibling](sibling_criterion.md) | Locations that are children of the same parent | ✔ | ✔ | ✔ | | | [Subtree](subtree_criterion.md) | Location subtree | ✔ | ✔ | ✔ | | | [TaxonomyEntryId](taxonomy_entry_id.md) | Content tagged with Entry ID | ✔ | ✔ | ✔ | | +| [TaxonomyNoEntries](taxonomy_no_entries.md) | Content with no entries assigned from a given taxonomy | ✔ | ✔ | ✔ | | +| [TaxonomySubtree](taxonomy_subtree.md) | Content assigned to a taxonomy entry or any of its descendants | ✔ | ✔ | | | | [UserEmail](useremail_criterion.md) | Email address of a User account | ✔ | ✔ | ✔ | | | [UserId](userid_criterion.md) | User ID | ✔ | ✔ | ✔ | | | [UserLogin](userlogin_criterion.md) | User login | ✔ | ✔ | ✔ | | diff --git a/docs/search/criteria_reference/taxonomy_no_entries.md b/docs/search/criteria_reference/taxonomy_no_entries.md new file mode 100644 index 0000000000..d9c68828f5 --- /dev/null +++ b/docs/search/criteria_reference/taxonomy_no_entries.md @@ -0,0 +1,29 @@ +--- +description: TaxonomyNoEntries Search Criterion +--- + +# TaxonomyNoEntries Criterion + +The [`TaxonomyNoEntries` Search Criterion](https://example.com/api/php_api/php_api_reference/classes/Ibexa-Contracts-Taxonomy-Search-Query-Criterion-TaxonomyNoEntries.html) searches for content that has no entries assigned from the specified [taxonomy](taxonomy.md). + +Use it when you need to find content items to which no taxonomy entries have been assigned (for example, articles without tags). +It is available for all supported search engines and in [repository filtering](search_api.md#repository-filtering) + +## Arguments + +- `taxonomy` - `string` representing the identifier of the taxonomy (for example, `tags` or `categories`) + +## Example + +### PHP + +The following example searches for articles that have no entries assigned in the `tags` taxonomy: + +```php hl_lines="11-14" +[[= include_file('code_samples/search/content/taxonomy_no_entries_criterion.php') =]] +``` + +The criteria limit the results to content matching all of the conditions listed below: + +- content has no entries assigned in the `tags` taxonomy +- content type is `article` diff --git a/docs/search/criteria_reference/taxonomy_subtree.md b/docs/search/criteria_reference/taxonomy_subtree.md new file mode 100644 index 0000000000..0566b11a3c --- /dev/null +++ b/docs/search/criteria_reference/taxonomy_subtree.md @@ -0,0 +1,26 @@ +--- +description: TaxonomySubtree Search Criterion +--- + +# TaxonomySubtree Criterion + +The [`TaxonomySubtree` Search Criterion](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Taxonomy-Search-Query-Criterion-TaxonomySubtree.html) searches for content assigned to the specified [taxonomy](taxonomy.md) entry or any of its descendants. + +## Arguments + +- `taxonomyEntryId` - `int` representing the ID of the taxonomy entry that is the root of the subtree + +## Example + +### PHP + +The following example searches for articles assigned to taxonomy entry with ID `42` or any of its child entries: + +```php hl_lines="11-14" +[[= include_file('code_samples/search/content/taxonomy_subtree_criterion.php') =]] +``` + +The criteria limit the results to content matching all of the conditions listed below: + +- content is assigned to taxonomy entry `42` or any of its descendants +- content type is `article` diff --git a/mkdocs.yml b/mkdocs.yml index b34d2cb2df..5c4e3605f9 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -568,6 +568,8 @@ nav: - Sibling: search/criteria_reference/sibling_criterion.md - Subtree: search/criteria_reference/subtree_criterion.md - TaxonomyEntryID: search/criteria_reference/taxonomy_entry_id.md + - TaxonomyNoEntries: search/criteria_reference/taxonomy_no_entries.md + - TaxonomySubtree: search/criteria_reference/taxonomy_subtree.md - UserEmail: search/criteria_reference/useremail_criterion.md - UserId: search/criteria_reference/userid_criterion.md - UserLogin: search/criteria_reference/userlogin_criterion.md