From 079180e5fe494a5045a6caf8f6382f9fb762e1c4 Mon Sep 17 00:00:00 2001 From: lukmzig Date: Thu, 5 Jun 2025 08:13:33 +0200 Subject: [PATCH 1/2] Add sort index field for documents --- config/pimcore/config.yaml | 2 ++ doc/01_Installation/02_Upgrade.md | 6 ++++++ .../SearchResult/DocumentSearchResultItem.php | 14 ++++++++++++++ .../Search/DocumentSearchResultDenormalizer.php | 1 + .../Serializer/Normalizer/DocumentNormalizer.php | 1 + 5 files changed, 24 insertions(+) diff --git a/config/pimcore/config.yaml b/config/pimcore/config.yaml index 5591d9f3..d92886f9 100644 --- a/config/pimcore/config.yaml +++ b/config/pimcore/config.yaml @@ -146,6 +146,8 @@ pimcore_generic_data_index: type: keyword href: type: keyword + index: + type: integer data_object: published: type: boolean diff --git a/doc/01_Installation/02_Upgrade.md b/doc/01_Installation/02_Upgrade.md index 3425e3e8..d341df46 100644 --- a/doc/01_Installation/02_Upgrade.md +++ b/doc/01_Installation/02_Upgrade.md @@ -2,6 +2,12 @@ Following steps are necessary during updating to newer versions. +## Upgrade to 2.1.0 +- Added support for Symfony 7 +- [Indexing] Added sort index for documents +- Execute the following command to reindex all elements to be able to use all new features: + ```bin/console generic-data-index:update:index -r``` + ## Upgrade to 2.0.0 - [Indexing] Added inherited fields indicator to data object indexing - [Indexing] Added functionality to enqueue dependent items diff --git a/src/Model/Search/Document/SearchResult/DocumentSearchResultItem.php b/src/Model/Search/Document/SearchResult/DocumentSearchResultItem.php index 3347cc6d..6adf0198 100644 --- a/src/Model/Search/Document/SearchResult/DocumentSearchResultItem.php +++ b/src/Model/Search/Document/SearchResult/DocumentSearchResultItem.php @@ -28,6 +28,8 @@ class DocumentSearchResultItem implements ElementSearchResultItemInterface private string $key; + private int $index; + private bool $published; private string $path; @@ -109,6 +111,18 @@ public function setKey(string $key): DocumentSearchResultItem return $this; } + public function getIndex(): int + { + return $this->index; + } + + public function setIndex(int $index): DocumentSearchResultItem + { + $this->index = $index; + + return $this; + } + public function isPublished(): bool { return $this->published; diff --git a/src/Service/Serializer/Denormalizer/Search/DocumentSearchResultDenormalizer.php b/src/Service/Serializer/Denormalizer/Search/DocumentSearchResultDenormalizer.php index 11637a35..9e7870f7 100644 --- a/src/Service/Serializer/Denormalizer/Search/DocumentSearchResultDenormalizer.php +++ b/src/Service/Serializer/Denormalizer/Search/DocumentSearchResultDenormalizer.php @@ -54,6 +54,7 @@ public function denormalize( ->setParentId(SystemField::PARENT_ID->getData($data)) ->setType(SystemField::TYPE->getData($data)) ->setKey(SystemField::KEY->getData($data)) + ->setIndex(SystemField::INDEX->getData($data)) ->setPath(SystemField::PATH->getData($data)) ->setPublished(SystemField::PUBLISHED->getData($data)) ->setFullPath(SystemField::FULL_PATH->getData($data)) diff --git a/src/Service/Serializer/Normalizer/DocumentNormalizer.php b/src/Service/Serializer/Normalizer/DocumentNormalizer.php index 2e597dcb..b8a01535 100644 --- a/src/Service/Serializer/Normalizer/DocumentNormalizer.php +++ b/src/Service/Serializer/Normalizer/DocumentNormalizer.php @@ -97,6 +97,7 @@ private function normalizeSystemFields(Document $document, bool $skipLazyLoadedF SystemField::PUBLISHED->value => $document->isPublished(), SystemField::TYPE->value => $document->getType(), SystemField::KEY->value => $document->getKey(), + SystemField::INDEX->value => $document->getIndex(), SystemField::PATH->value => $document->getPath(), SystemField::FULL_PATH->value => $document->getRealFullPath(), SystemField::USER_OWNER->value => $document->getUserOwner(), From d64866989c050dce51e7cd46e69c7134c8648d0d Mon Sep 17 00:00:00 2001 From: lukmzig Date: Thu, 5 Jun 2025 09:21:11 +0200 Subject: [PATCH 2/2] add missing docs --- config/pimcore/config.yaml | 4 ++-- .../05_Search_Modifiers/README.md | 10 +++++----- .../Search/Modifier/Sort/TreeSortHandlers.php | 5 ++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/config/pimcore/config.yaml b/config/pimcore/config.yaml index d92886f9..584a1dce 100644 --- a/config/pimcore/config.yaml +++ b/config/pimcore/config.yaml @@ -98,6 +98,8 @@ pimcore_generic_data_index: document: published: type: boolean + index: + type: integer controller: type: keyword template: @@ -146,8 +148,6 @@ pimcore_generic_data_index: type: keyword href: type: keyword - index: - type: integer data_object: published: type: boolean diff --git a/doc/04_Searching_For_Data_In_Index/05_Search_Modifiers/README.md b/doc/04_Searching_For_Data_In_Index/05_Search_Modifiers/README.md index 0fcfd2f5..8e3582cd 100644 --- a/doc/04_Searching_For_Data_In_Index/05_Search_Modifiers/README.md +++ b/doc/04_Searching_For_Data_In_Index/05_Search_Modifiers/README.md @@ -57,12 +57,12 @@ $search->addModifier(new ParentIdFilter(1)) If multiple sort modifiers are added to the search, the order of the modifiers is important. The search result will be sorted by the first added modifier first, then by the second added modifier and so on. -| Modifier | Modifier Category | Description | -|----------------------------------------------------------------------------------------------------------------------------------------------|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| [OrderByFullPath](https://github.com/pimcore/generic-data-index-bundle/blob/1.x/src/Model/Search/Modifier/Sort/Tree/OrderByFullPath.php) | Tree related sorting | Order by full path (including element key) | +| Modifier | Modifier Category | Description | +|----------------------------------------------------------------------------------------------------------------------------------------------|------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [OrderByFullPath](https://github.com/pimcore/generic-data-index-bundle/blob/1.x/src/Model/Search/Modifier/Sort/Tree/OrderByFullPath.php) | Tree related sorting | Order by full path (including element key) | | [OrderByField](https://github.com/pimcore/generic-data-index-bundle/blob/1.x/src/Model/Search/Modifier/Sort/OrderByField.php) | Field based sorting | Order by given field name.
If `$enablePqlFieldNameResolution` is set to true (default) [Pimcore Query Language](https://github.com/pimcore/generic-data-index-bundle/blob/1.x/src/Model/Search/Modifier/Sort/OrderByField.php) field name resolution logic is enabled. Therefore it's possible to use short field names then instead of specifying the full indexed path. | -| [OrderByPageNumber](https://github.com/pimcore/generic-data-index-bundle/blob/1.x/src/Model/Search/Modifier/Sort/Tree/OrderByPageNumber.php) | Search related sorting | Use inverted search for large amounts of data (this modifier is added to the search when there are at least 1000 results by default, and page number is above the half of total pages. Furthermore, existing sorting has to be already applied.) | -| [OrderByIndexField](https://github.com/pimcore/generic-data-index-bundle/blob/1.x/src/Model/Search/Modifier/Sort/Tree/OrderByIndexField.php) | Search related sorting | Order by object tree index for custom tree sorting. This modifier is currently applied only for data objects! | +| [OrderByPageNumber](https://github.com/pimcore/generic-data-index-bundle/blob/1.x/src/Model/Search/Modifier/Sort/Tree/OrderByPageNumber.php) | Search related sorting | Use inverted search for large amounts of data (this modifier is added to the search when there are at least 1000 results by default, and page number is above the half of total pages. Furthermore, existing sorting has to be already applied.) | +| [OrderByIndexField](https://github.com/pimcore/generic-data-index-bundle/blob/1.x/src/Model/Search/Modifier/Sort/Tree/OrderByIndexField.php) | Search related sorting | Order by element tree index for custom tree sorting. This modifier is currently applied only for data objects and documents! | ### Aggregations diff --git a/src/SearchIndexAdapter/DefaultSearch/Search/Modifier/Sort/TreeSortHandlers.php b/src/SearchIndexAdapter/DefaultSearch/Search/Modifier/Sort/TreeSortHandlers.php index da88f1b3..7e1e0bfc 100644 --- a/src/SearchIndexAdapter/DefaultSearch/Search/Modifier/Sort/TreeSortHandlers.php +++ b/src/SearchIndexAdapter/DefaultSearch/Search/Modifier/Sort/TreeSortHandlers.php @@ -20,6 +20,7 @@ use Pimcore\Bundle\GenericDataIndexBundle\Model\DefaultSearch\Sort\FieldSort; use Pimcore\Bundle\GenericDataIndexBundle\Model\DefaultSearch\Sort\FieldSortList; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\DataObjectSearch; +use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Document\DocumentSearch; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\OrderByPageNumber; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\Tree\OrderByFullPath; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\Tree\OrderByIndexField; @@ -97,7 +98,9 @@ public function handleIndexSort( OrderByIndexField $indexSort, SearchModifierContextInterface $context ): void { - if (!$context->getOriginalSearch() instanceof DataObjectSearch) { + if (!$context->getOriginalSearch() instanceof DataObjectSearch && + !$context->getOriginalSearch() instanceof DocumentSearch + ) { return; }