Skip to content

Commit

Permalink
Add element search services
Browse files Browse the repository at this point in the history
  • Loading branch information
markus-moser committed May 24, 2024
1 parent 8926dbb commit e9b1187
Show file tree
Hide file tree
Showing 50 changed files with 1,017 additions and 172 deletions.
11 changes: 11 additions & 0 deletions config/pimcore/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pimcore_generic_data_index:
general:
id:
type: long
elementType:
type: keyword
parentId:
type: long
creationDate:
Expand Down Expand Up @@ -113,6 +115,15 @@ pimcore_generic_data_index:
type: boolean
hasWorkflowWithPermissions:
type: boolean
dependencies:
type: object
properties:
asset:
type: long
document:
type: long
object:
type: long
document:
published:
type: boolean
Expand Down
8 changes: 8 additions & 0 deletions config/services/dependency.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

Pimcore\Bundle\GenericDataIndexBundle\Service\Dependency\DependencyServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\Dependency\DependencyService
5 changes: 5 additions & 0 deletions config/services/search-index-adapter/open-search.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ services:
arguments:
$openSearchClient: '@generic-data-index.opensearch-client'

Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\IndexAliasServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\OpenSearch\IndexAliasService
arguments:
$openSearchClient: '@generic-data-index.opensearch-client'

Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\OpenSearch\Search\SearchExecutionServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\OpenSearch\Search\SearchExecutionService
arguments:
Expand Down
5 changes: 4 additions & 1 deletion config/services/search/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ services:
arguments:
- [ ]

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\IndexHandler\DocumentIndexHandler: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\IndexHandler\DocumentIndexHandler: ~

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\GlobalIndexAliasServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\GlobalIndexAliasService
4 changes: 4 additions & 0 deletions config/services/search/search-services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ services:
Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Document\DocumentSearchServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Document\DocumentSearchService

Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Element\ElementSearchServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Element\ElementSearchService

Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\DataObject\SearchHelper: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Asset\SearchHelper: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Document\SearchHelper: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Element\SearchHelper: ~

Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\SearchProviderInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\SearchProvider
Expand Down
8 changes: 8 additions & 0 deletions doc/01_Installation/02_Upgrade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Upgrade Information

Following steps are necessary during updating to newer versions.

## Upgrade to 1.1.0
- Execute the following command to reindex all elements to be able to use all new features:

```bin/console generic-data-index:update:index```
20 changes: 20 additions & 0 deletions doc/04_Searching_For_Data_In_Index/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ public function searchAction(SearchProviderInterface $searchProvider, DocumentSe
}
```

## Element Search Service

The element search service can be used to search for assets, data objects and documents at the same time.

- Example: This example loads all elements and orders them by their full path.
```php
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\SearchProviderInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Element\ElementSearchServiceInterface;

public function searchAction(SearchProviderInterface $searchProvider, ElementSearchServiceInterface $elementSearchService)
{
$elementSearch = $searchProvider->createElementSearch()
->addModifier(new OrderByFullPath())
->setPageSize(50)
->setPage(1);

$searchResult = $elementSearchService->search($elementSearch);
}
```

## Search Modifiers

To influence the data which gets fetched its possible to use so-called search modifiers.
Expand Down
34 changes: 34 additions & 0 deletions src/Command/Update/IndexUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Exception;
use Pimcore\Bundle\GenericDataIndexBundle\Exception\CommandAlreadyRunningException;
use Pimcore\Bundle\GenericDataIndexBundle\Exception\IdNotFoundException;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\GlobalIndexAliasServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueue\EnqueueServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexUpdateServiceInterface;
use Pimcore\Console\AbstractCommand;
Expand All @@ -42,10 +43,14 @@ final class IndexUpdateCommand extends AbstractCommand

private const OPTION_RECREATE_INDEX = 'recreate_index';

private const UPDATE_GLOBAL_ALIASES_ONLY = 'update-global-aliases-only';

private IndexUpdateServiceInterface $indexUpdateService;

private EnqueueServiceInterface $enqueueService;

private GlobalIndexAliasServiceInterface $globalIndexAliasService;

#[Required]
public function setIndexUpdateService(IndexUpdateServiceInterface $indexUpdateService): void
{
Expand All @@ -58,6 +63,12 @@ public function setEnqueueService(EnqueueServiceInterface $enqueueService): void
$this->enqueueService = $enqueueService;
}

#[Required]
public function setGlobalIndexAliasService(GlobalIndexAliasServiceInterface $globalIndexAliasService): void
{
$this->globalIndexAliasService = $globalIndexAliasService;
}

protected function configure(): void
{
$this
Expand All @@ -83,6 +94,13 @@ protected function configure(): void
'Delete and recreate search indices',
null
)
->addOption(
self::UPDATE_GLOBAL_ALIASES_ONLY,
null,
InputOption::VALUE_NONE,
'Updates the global index aliases for data-object and element-search indices only.',
null
)
->setDescription(
'Updates index/mapping for all classDefinitions/asset without ' .
'deleting them. Adds there elements to index queue.'
Expand All @@ -101,6 +119,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
);
}

if ($input->getOption(self::UPDATE_GLOBAL_ALIASES_ONLY)) {
$this->updateGlobalIndexAliases();
return self::SUCCESS;
}

$this->indexUpdateService->setReCreateIndex($input->getOption(self::OPTION_RECREATE_INDEX));

$updateAll = true;
Expand Down Expand Up @@ -173,11 +196,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
);

$this->enqueueService->dispatchQueueMessages(true);
$this->updateGlobalIndexAliases();

$this->release();

$this->output->writeln('<info>Finished</info>', OutputInterface::VERBOSITY_VERBOSE);

return self::SUCCESS;
}

private function updateGlobalIndexAliases(): void
{
$this->output->writeln(
'<info>Update global aliases</info>',
OutputInterface::VERBOSITY_VERBOSE
);
$this->globalIndexAliasService->updateDataObjectAlias();
$this->globalIndexAliasService->updateElementSearchAlias();
}
}
2 changes: 2 additions & 0 deletions src/Enum/SearchIndex/FieldCategory/SystemField.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum SystemField: string
use FieldCategory\SystemField\SystemFieldTrait;

case ID = 'id';
case ELEMENT_TYPE = 'elementType';
case PARENT_ID = 'parentId';
case CREATION_DATE = 'creationDate';
case MODIFICATION_DATE = 'modificationDate';
Expand All @@ -47,6 +48,7 @@ enum SystemField: string
case IS_LOCKED = 'isLocked';
case HAS_WORKFLOW_WITH_PERMISSIONS = 'hasWorkflowWithPermissions';
case FILE_SIZE = 'fileSize';
case DEPENDENCIES = 'dependencies';

/**
* Not persisted in search index but dynamically calculated
Expand Down
1 change: 1 addition & 0 deletions src/Enum/SearchIndex/IndexName.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ enum IndexName: string
case ASSET = 'asset';
case DATA_OBJECT = 'data-object';
case DOCUMENT = 'document';
case ELEMENT_SEARCH = 'element-search';
}
26 changes: 26 additions & 0 deletions src/Exception/ElementSearchException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\GenericDataIndexBundle\Exception;

use RuntimeException;

/**
* @internal
*/
final class ElementSearchException extends RuntimeException implements GenericDataIndexBundleExceptionInterface
{
}
11 changes: 9 additions & 2 deletions src/Model/Search/Asset/SearchResult/AssetSearchResultItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

namespace Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\SearchResult;

use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\ElementType;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\ElementSearchResultItemInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Permission\AssetPermissions;

class AssetSearchResultItem
class AssetSearchResultItem implements ElementSearchResultItemInterface
{
private int $id;

Expand Down Expand Up @@ -59,6 +61,11 @@ class AssetSearchResultItem

private AssetPermissions $permissions;

public function getElementType(): ElementType
{
return ElementType::ASSET;
}

public function getId(): int
{
return $this->id;
Expand Down Expand Up @@ -172,7 +179,7 @@ public function getUserModification(): ?int
return $this->userModification;
}

public function setUserModification(int $userModification): AssetSearchResultItem
public function setUserModification(?int $userModification): AssetSearchResultItem
{
$this->userModification = $userModification;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

namespace Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\SearchResult;

use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\ElementType;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\ElementSearchResultItemInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Permission\DataObjectPermissions;

class DataObjectSearchResultItem
class DataObjectSearchResultItem implements ElementSearchResultItemInterface
{
private int $id;

Expand Down Expand Up @@ -56,6 +58,11 @@ class DataObjectSearchResultItem

private DataObjectPermissions $permissions;

public function getElementType(): ElementType
{
return ElementType::DATA_OBJECT;
}

public function getId(): int
{
return $this->id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

namespace Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Document\SearchResult;

use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\ElementType;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\ElementSearchResultItemInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Permission\DocumentPermissions;

class DocumentSearchResultItem
class DocumentSearchResultItem implements ElementSearchResultItemInterface
{
private int $id;

Expand Down Expand Up @@ -56,6 +58,11 @@ class DocumentSearchResultItem

private DocumentPermissions $permissions;

public function getElementType(): ElementType
{
return ElementType::DOCUMENT;
}

public function getId(): int
{
return $this->id;
Expand Down
23 changes: 23 additions & 0 deletions src/Model/Search/Element/ElementSearch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Element;

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\BaseSearch;

final class ElementSearch extends BaseSearch
{
}
Loading

0 comments on commit e9b1187

Please sign in to comment.