-
Notifications
You must be signed in to change notification settings - Fork 81
IBX-10885: Document Content Type search API #2946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dabrt
wants to merge
3
commits into
5.0
Choose a base branch
from
IBX-10885
base: 5.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+138
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| <?php declare(strict_types=1); | ||
|
|
||
| namespace App\Command; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\ContentTypeService; | ||
| use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery; | ||
| use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion; | ||
| use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause; | ||
| use Symfony\Component\Console\Attribute\AsCommand; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| #[AsCommand( | ||
| name: 'doc:find_content_types', | ||
| description: 'Lists content types that match specific criteria.' | ||
| )] | ||
| class FindContentTypeCommand extends Command | ||
| { | ||
| public function __construct(private readonly ContentTypeService $contentTypeService) | ||
| { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| protected function execute(InputInterface $input, OutputInterface $output): int | ||
| { | ||
| // Find content types whose identifier is "folder" or "article", | ||
| // or content type "user" | ||
| $query = new ContentTypeQuery( | ||
| new Criterion\LogicalOr([ | ||
| new Criterion\LogicalAnd([ | ||
| new Criterion\ContentTypeIdentifier(['folder', 'article']), | ||
| ]), | ||
| new Criterion\ContentTypeIdentifier(['user']), | ||
| ]), | ||
| [ | ||
| new SortClause\Id(), | ||
| new SortClause\Identifiers(), | ||
| new SortClause\Name(), | ||
| ] | ||
| ); | ||
|
|
||
| $searchResult = $this->contentTypeService->findContentTypes($query); | ||
|
|
||
| $output->writeln('Found ' . $searchResult->totalCount . ' content types:'); | ||
|
|
||
| foreach ($searchResult->searchHits as $searchHit) { | ||
| $contentType = $searchHit->valueObject; | ||
| $output->writeln(sprintf( | ||
| '- [%d] %s (identifier: %s)', | ||
| $contentType->id, | ||
| $contentType->getName(), | ||
| $contentType->identifier | ||
| )); | ||
| } | ||
|
|
||
| return Command::SUCCESS; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
docs/search/content_type_search_reference/content_type_criteria.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| description: Content Type Search Criteria help define and fine-tune search queries for content types. | ||
| page_type: reference | ||
| month_change: true | ||
| --- | ||
|
|
||
| # Content Type Search Criteria reference | ||
|
|
||
| Content Type Search Criteria are only supported by Content Type Search (`ContentTypeService::findContentTypes`). | ||
|
|
||
| | Criterion | Description | | ||
| |-------|-------------| | ||
| | [ContainsFieldDefinitionId](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-ContainsFieldDefinitionId.html) | Matches content types that contain a field definition with the specified ID. | | ||
| | [ContentTypeGroupId](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-ContentTypeGroupId.html) | Matches content types by their assigned group ID. | | ||
barw4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| | [ContentTypeId](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-ContentTypeId.html) | Matches content types by their ID. | | ||
| | [ContentTypeIdentifier](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-ContentTypeIdentifier.html) | Matches content types by their identifier. | | ||
| | [IsSystem](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-IsSystem.html) | Matches content types based on whether the group they belong to is system or not. | | ||
| | [LogicalAnd](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-LogicalAnd.html) | Implements a logical AND Criterion. It matches if ALL of the provided Criteria match. | | ||
| | [LogicalOr](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-LogicalOr.html) | Implements a logical OR Criterion. It matches if at least one of the provided Criteria matches. | | ||
| | [LogicalNot](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-LogicalNot.html) | Implements a logical NOT Criterion. It matches if the provided Criterion doesn't match. | | ||
|
|
||
| For an example that shows how you can use the criteria to find content types, see [Finding and filtering content types](managing_content.md#finding-and-filtering-content-types). | ||
26 changes: 26 additions & 0 deletions
26
docs/search/content_type_search_reference/content_type_sort_clauses.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- | ||
| description: Content Type Search Sort Clauses | ||
| month_change: true | ||
| --- | ||
|
|
||
| # Content Type Search Sort Clauses | ||
|
|
||
| Content Type Search Sort Clauses are the sorting options for content types. | ||
| They're only supported by [Content Type Search (`ContentTypeService::findContentTypes`)](managing_content.md#finding-and-filtering-content-types). | ||
|
|
||
| Sort Clauses are found in the [`Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause`](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-SortClause.html) namespace: | ||
|
|
||
| | Name | Description | | ||
| | --- | --- | | ||
| | [Id](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-SortClause-Id.html)| Sort by content type's id | | ||
| | [Identifier](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-SortClause-Identifier.html)| Sort by content type's identifier | | ||
| | [Name](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-SortClause-Name.html)| Sort by content type's name | | ||
|
|
||
|
|
||
| The following example shows how to use them to sort the searched content items: | ||
|
|
||
| ```php hl_lines="37-39" | ||
| [[= include_file('code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php') =]] | ||
| ``` | ||
|
|
||
| You can change the default sorting order by using the `SORT_ASC` and `SORT_DESC` constants from [`AbstractSortClause`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-CoreSearch-Values-Query-AbstractSortClause.html#constants). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make sense to use some different criterion here -> maybe
ContentTypeGroupName. The current one doesn't make a lot of sense because it could be simply put into one criterion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just relied on an example given in your PR. We can add ContentTypeGroupName in a follow up PR, WDYS?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use something else than
new Criterion\ContentTypeIdentifier(['user']),it can be evenContentTypeGroupId. The current example is not a proper one, these criteria:shouldn't be composed like that.
LogicalAnddoesn't make sense without at least two criterions inside. All this logic could be replaced with:new Criterion\ContentTypeIdentifier(['folder', 'article', 'user'])Let's keep this example grounded