Skip to content

Commit 294c7cc

Browse files
authored
[Documents] Add sort index (#330)
* Add sort index field for documents * add missing docs
1 parent bea24b6 commit 294c7cc

File tree

7 files changed

+33
-6
lines changed

7 files changed

+33
-6
lines changed

config/pimcore/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ pimcore_generic_data_index:
9898
document:
9999
published:
100100
type: boolean
101+
index:
102+
type: integer
101103
controller:
102104
type: keyword
103105
template:

doc/01_Installation/02_Upgrade.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Following steps are necessary during updating to newer versions.
44

5+
## Upgrade to 2.1.0
6+
- Added support for Symfony 7
7+
- [Indexing] Added sort index for documents
8+
- Execute the following command to reindex all elements to be able to use all new features:
9+
```bin/console generic-data-index:update:index -r```
10+
511
## Upgrade to 2.0.0
612
- [Indexing] Added inherited fields indicator to data object indexing
713
- [Indexing] Added functionality to enqueue dependent items

doc/04_Searching_For_Data_In_Index/05_Search_Modifiers/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ $search->addModifier(new ParentIdFilter(1))
5757

5858
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.
5959

60-
| Modifier | Modifier Category | Description |
61-
|----------------------------------------------------------------------------------------------------------------------------------------------|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
62-
| [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) |
60+
| Modifier | Modifier Category | Description |
61+
|----------------------------------------------------------------------------------------------------------------------------------------------|------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
62+
| [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) |
6363
| [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.<br/>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. |
64-
| [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.) |
65-
| [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! |
64+
| [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.) |
65+
| [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! |
6666

6767
### Aggregations
6868

src/Model/Search/Document/SearchResult/DocumentSearchResultItem.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class DocumentSearchResultItem implements ElementSearchResultItemInterface
2828

2929
private string $key;
3030

31+
private int $index;
32+
3133
private bool $published;
3234

3335
private string $path;
@@ -109,6 +111,18 @@ public function setKey(string $key): DocumentSearchResultItem
109111
return $this;
110112
}
111113

114+
public function getIndex(): int
115+
{
116+
return $this->index;
117+
}
118+
119+
public function setIndex(int $index): DocumentSearchResultItem
120+
{
121+
$this->index = $index;
122+
123+
return $this;
124+
}
125+
112126
public function isPublished(): bool
113127
{
114128
return $this->published;

src/SearchIndexAdapter/DefaultSearch/Search/Modifier/Sort/TreeSortHandlers.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Pimcore\Bundle\GenericDataIndexBundle\Model\DefaultSearch\Sort\FieldSort;
2121
use Pimcore\Bundle\GenericDataIndexBundle\Model\DefaultSearch\Sort\FieldSortList;
2222
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\DataObjectSearch;
23+
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Document\DocumentSearch;
2324
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\OrderByPageNumber;
2425
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\Tree\OrderByFullPath;
2526
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\Tree\OrderByIndexField;
@@ -97,7 +98,9 @@ public function handleIndexSort(
9798
OrderByIndexField $indexSort,
9899
SearchModifierContextInterface $context
99100
): void {
100-
if (!$context->getOriginalSearch() instanceof DataObjectSearch) {
101+
if (!$context->getOriginalSearch() instanceof DataObjectSearch &&
102+
!$context->getOriginalSearch() instanceof DocumentSearch
103+
) {
101104
return;
102105
}
103106

src/Service/Serializer/Denormalizer/Search/DocumentSearchResultDenormalizer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function denormalize(
5454
->setParentId(SystemField::PARENT_ID->getData($data))
5555
->setType(SystemField::TYPE->getData($data))
5656
->setKey(SystemField::KEY->getData($data))
57+
->setIndex(SystemField::INDEX->getData($data))
5758
->setPath(SystemField::PATH->getData($data))
5859
->setPublished(SystemField::PUBLISHED->getData($data))
5960
->setFullPath(SystemField::FULL_PATH->getData($data))

src/Service/Serializer/Normalizer/DocumentNormalizer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ private function normalizeSystemFields(Document $document, bool $skipLazyLoadedF
9797
SystemField::PUBLISHED->value => $document->isPublished(),
9898
SystemField::TYPE->value => $document->getType(),
9999
SystemField::KEY->value => $document->getKey(),
100+
SystemField::INDEX->value => $document->getIndex(),
100101
SystemField::PATH->value => $document->getPath(),
101102
SystemField::FULL_PATH->value => $document->getRealFullPath(),
102103
SystemField::USER_OWNER->value => $document->getUserOwner(),

0 commit comments

Comments
 (0)