Skip to content

Commit

Permalink
Merge branch '1.0' into 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
markus-moser committed Jun 13, 2024
2 parents 1d80d59 + 018d104 commit c12f0a7
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 7 deletions.
2 changes: 2 additions & 0 deletions config/services/search-index-adapter/open-search.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ services:

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

Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\IndexMappingServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\OpenSearch\IndexMappingService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ services:
shared: false
tags:
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "quantityValue" }

Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\OpenSearch\DataObject\FieldDefinitionAdapter\InputQuantityValueAdapter:
shared: false
tags:
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "inputQuantityValue" }

Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\OpenSearch\DataObject\FieldDefinitionAdapter\BooleanAdapter:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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\SearchIndexAdapter\OpenSearch\DataObject\FieldDefinitionAdapter;

use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\OpenSearch\AttributeType;

/**
* @internal
*/
final class InputQuantityValueAdapter extends AbstractAdapter
{
public function getIndexMapping(): array
{
return [
'properties' => [
'value' => [
'type' => AttributeType::KEYWORD->value,
],
'unitId' => [
'type' => AttributeType::TEXT->value,
],
],
];
}
}
35 changes: 28 additions & 7 deletions src/SearchIndexAdapter/OpenSearch/IndexStatsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\OpenSearch;

use Exception;
use OpenSearch\Client;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Stats\IndexStats;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Stats\IndexStatsIndex;
use Pimcore\Bundle\GenericDataIndexBundle\Repository\IndexQueueRepository;
Expand All @@ -30,9 +31,10 @@ final class IndexStatsService implements IndexStatsServiceInterface
use LoggerAwareTrait;

public function __construct(
protected readonly SearchIndexConfigServiceInterface $searchIndexConfigService,
protected readonly IndexQueueRepository $indexQueueRepository,
protected readonly SearchIndexServiceInterface $openSearchService,
private readonly SearchIndexConfigServiceInterface $searchIndexConfigService,
private readonly IndexQueueRepository $indexQueueRepository,
private readonly SearchIndexServiceInterface $openSearchService,
private readonly Client $openSearchClient,
) {
}

Expand All @@ -43,12 +45,31 @@ public function getStats(): IndexStats
$this->searchIndexConfigService->getIndexPrefix() . '*'
);

$aggregationResult = $this->openSearchClient->search([
'index' => $this->searchIndexConfigService->getIndexPrefix() . '*',
'body' => [
'size' => 0,
'aggs' => [
'indices' => [
'terms' => [
'field' => '_index',
'size' => 10000,
'order' => [
'_key' => 'asc',
],
],
],
],
],
]);

$indices = [];
foreach ($allStats['indices'] as $indexName => $index) {
foreach ($aggregationResult['aggregations']['indices']['buckets'] as $bucket) {
$sizeInBytes = (int)($allStats['indices'][$bucket['key']]['total']['store']['size_in_bytes'] ?? 0);
$indices[] = new IndexStatsIndex(
indexName: $indexName,
itemsCount: $index['total']['docs']['count'],
sizeInKb: round(((int)$index['total']['store']['size_in_bytes'] / 1024), 2)
indexName: $bucket['key'],
itemsCount: $bucket['doc_count'],
sizeInKb: round(($sizeInBytes / 1024), 2)
);
}

Expand Down

0 comments on commit c12f0a7

Please sign in to comment.