-
Notifications
You must be signed in to change notification settings - Fork 19
IBX-5111: Introduced custom find and result extracting capabilities #239
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
Closed
Closed
Changes from all commits
Commits
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
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
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
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
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,62 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Contracts\Core\Repository\Values\Search; | ||
|
|
||
| final class SearchContext implements SearchContextInterface | ||
| { | ||
| /** @var array{}|array{languages: array<string>, useAlwaysAvailable: bool} */ | ||
| private array $languageFilter; | ||
|
|
||
| private bool $filterOnUserPermissions; | ||
|
|
||
| /** @var array<string> */ | ||
| private array $documentTypeIdentifiers; | ||
|
|
||
| /** | ||
| * @param array{}|array{languages: array<string>, useAlwaysAvailable: bool} $languageFilter | ||
| * @param array<string> $documentTypeIdentifiers | ||
| */ | ||
| public function __construct( | ||
| array $languageFilter = [], | ||
| bool $filterOnUserPermissions = true, | ||
| array $documentTypeIdentifiers = [] | ||
| ) { | ||
| $this->languageFilter = $languageFilter; | ||
| $this->filterOnUserPermissions = $filterOnUserPermissions; | ||
| $this->documentTypeIdentifiers = $documentTypeIdentifiers; | ||
| } | ||
|
|
||
| public function setLanguageFilter(array $languageFilter): void | ||
| { | ||
| $this->languageFilter = $languageFilter; | ||
| } | ||
|
|
||
| public function getLanguageFilter(): array | ||
| { | ||
| return $this->languageFilter; | ||
| } | ||
|
|
||
| public function setFilterOnUserPermissions(bool $filterOnUserPermissions): void | ||
| { | ||
| $this->filterOnUserPermissions = $filterOnUserPermissions; | ||
| } | ||
|
|
||
| public function doesFilterOnUserPermissions(): bool | ||
| { | ||
| return $this->filterOnUserPermissions; | ||
| } | ||
|
|
||
| /** | ||
| * @return array<string> | ||
| */ | ||
| public function getDocumentTypeIdentifiers(): array | ||
| { | ||
| return $this->documentTypeIdentifiers; | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
src/contracts/Repository/Values/Search/SearchContextInterface.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,31 @@ | ||||||||||||||
| <?php | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||||||||||||||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||||||||||||||
| */ | ||||||||||||||
| declare(strict_types=1); | ||||||||||||||
|
|
||||||||||||||
| namespace Ibexa\Contracts\Core\Repository\Values\Search; | ||||||||||||||
|
|
||||||||||||||
| interface SearchContextInterface | ||||||||||||||
| { | ||||||||||||||
| /** | ||||||||||||||
| * @param array{}|array{languages: array<string>, useAlwaysAvailable: bool} $languageFilter | ||||||||||||||
| */ | ||||||||||||||
|
Comment on lines
+13
to
+15
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| public function setLanguageFilter(array $languageFilter): void; | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * @return array{}|array{languages: array<string>, useAlwaysAvailable: bool} | ||||||||||||||
| */ | ||||||||||||||
| public function getLanguageFilter(): array; | ||||||||||||||
|
|
||||||||||||||
| public function setFilterOnUserPermissions(bool $filterOnUserPermissions): void; | ||||||||||||||
|
|
||||||||||||||
| public function doesFilterOnUserPermissions(): bool; | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * @return array<string> | ||||||||||||||
| */ | ||||||||||||||
| public function getDocumentTypeIdentifiers(): array; | ||||||||||||||
| } | ||||||||||||||
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
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
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
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,20 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| namespace Ibexa\Core\Repository\Mapper; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit; | ||
| use Ibexa\Contracts\Core\Repository\Values\Search\SearchContextInterface; | ||
|
|
||
| interface SearchHitMapperInterface | ||
| { | ||
| /** | ||
| * @return mixed | ||
| */ | ||
| public function buildObjectOnSearchHit(SearchHit $hit, SearchContextInterface $context = null); | ||
|
|
||
| public function supports(SearchHit $hit, SearchContextInterface $context = null): bool; | ||
| } |
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,56 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| namespace Ibexa\Core\Repository\Mapper; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit; | ||
| use Ibexa\Core\Base\Exceptions\InvalidArgumentException; | ||
|
|
||
| final class SearchHitMapperRegistry implements SearchHitMapperRegistryInterface | ||
| { | ||
| /** @var iterable<\Ibexa\Core\Repository\Mapper\SearchHitMapperInterface> */ | ||
| private iterable $mappers; | ||
|
|
||
| /** | ||
| * @param iterable<\Ibexa\Core\Repository\Mapper\SearchHitMapperInterface> $mappers | ||
| */ | ||
| public function __construct(iterable $mappers) | ||
| { | ||
| $this->mappers = $mappers; | ||
| } | ||
|
|
||
| public function hasMapper(SearchHit $hit): bool | ||
| { | ||
| return $this->findMappers($hit) !== null; | ||
| } | ||
|
|
||
| public function getMapper(SearchHit $hit): SearchHitMapperInterface | ||
| { | ||
| if (!$this->hasMapper($hit)) { | ||
| throw new InvalidArgumentException( | ||
| '$hit', | ||
| sprintf( | ||
| 'undefined %s for search hit %s', | ||
| SearchHitMapperInterface::class, | ||
| get_debug_type($hit->valueObject) | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| return $this->findMappers($hit); | ||
| } | ||
|
|
||
| private function findMappers(SearchHit $hit): ?SearchHitMapperInterface | ||
| { | ||
| foreach ($this->mappers as $mapper) { | ||
| if ($mapper->supports($hit)) { | ||
| return $mapper; | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/lib/Repository/Mapper/SearchHitMapperRegistryInterface.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,16 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| namespace Ibexa\Core\Repository\Mapper; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit; | ||
|
|
||
| interface SearchHitMapperRegistryInterface | ||
| { | ||
| public function hasMapper(SearchHit $hit): bool; | ||
|
|
||
| public function getMapper(SearchHit $hit): SearchHitMapperInterface; | ||
| } |
Oops, something went wrong.
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.
Note that Context implies that there might be parameters that are outside of our current expectations that are used by third party code. In my opinion it should be flexible enough that any underlying search engine could pick parameters that it is interested in.