diff --git a/composer.json b/composer.json index 8de837ea..e58ddfdc 100644 --- a/composer.json +++ b/composer.json @@ -43,10 +43,7 @@ "autoload": { "psr-4": { "Pimcore\\Bundle\\GenericDataIndexBundle\\": "src/" - }, - "files": [ - "src/autoload.php" - ] + } }, "autoload-dev": { "psr-4": { diff --git a/doc/01_Installation/02_Upgrade.md b/doc/01_Installation/02_Upgrade.md index f3d3400e..a3a6e25c 100644 --- a/doc/01_Installation/02_Upgrade.md +++ b/doc/01_Installation/02_Upgrade.md @@ -2,6 +2,39 @@ Following steps are necessary during updating to newer versions. +## Upgrade to 2.0.0 +- [Indexing] Added inherited fields indicator to data object indexing +- [Indexing] Added functionality to enqueue dependent items + +### BC-Breaks +- Removed deprecated alias `generic-data-index.opensearch-client` and replaced it with `generic-data-index.search-client` +- Removed all deprecated classes from OpenSearch namespaces and replaced them with DefaultSearch namespace instead. + - `Pimcore\Bundle\GenericDataIndexBundle\Model\OpenSearch` -> `Pimcore\Bundle\GenericDataIndexBundle\Model\DefaultSearch` + - `Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\OpenSearch` -> `Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\DefaultSearch` +- Removed deprecated class `Pimcore\Bundle\GenericDataIndexBundle\Exception\OpenSearch\SearchFailedException` please use `Pimcore\Bundle\GenericDataIndexBundle\Exception\OpenSearch\SearchFailedException` instead +- Removed deprecated class `Pimcore\Bundle\GenericDataIndexBundle\Attribute\OpenSearch\AsSearchModifierHandler` please use `Pimcore\Bundle\GenericDataIndexBundle\Attribute\Search\AsSearchModifierHandler` instead +- Removed deprecated class `Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\OpenSearch\Asset\FieldDefinitionAdapter\AbstractAdapter` please use `Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\DefaultSearch\Asset\FieldDefinitionAdapter\AbstractAdapter` instead +- Removed deprecated class `Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\OpenSearch\DataObject\FieldDefinitionAdapter\AbstractAdapter` please use `Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\DefaultSearch\DataObject\FieldDefinitionAdapter\AbstractAdapter` instead +- Added default prefix `data-object_` prefix to all data object class definition index names. This change is necessary to avoid conflicts with other index names. +- Add element type to the `getIds` method of `Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Element\SearchResult\ElementSearchResult` + +#### Interface changes +- Added `PermissionTypes $permissionType` parameter with default type `PermissionTypes::LIST` to +- `AssetSearchServiceInterface::search` method +- `DocumentSearchServiceInterface::search` method +- `DataObjectSearchServiceInterface::search` method +- `ElementSearchServiceInterface::search` method +- Search services `byId` methods now return elements based on the `PermissionTypes::VIEW` permission +- Added type specific interfaces for searches to avoid mixing up different search types in search services + - `AssetSearch` now implements `AssetSearchInterface` + - `DocumentSearch` now implements `DocumentSearchInterface` + - `ElementSearch` now implements `ElementSearchInterface` +- Search services now require the specific search type for the search + - `AssetSearchServiceInterface::search` now requires a `AssetSearchInterface` + - `DocumentSearchServiceInterface::search` now requires a `DocumentSearchInterface` + - `ElementSearchServiceInterface::search` now requires a `ElementSearchInterface` +- `SearchProviderInterface` now returns type specific search interfaces + ## Upgrade to 1.3.0 - [Indexing] Added support for Elasticsearch in parallel to Opensearch. Opensearch remains the default search technology. If you are using Elasticsearch, you need to update your symfony configuration as follows: ```yml @@ -21,25 +54,4 @@ The new service alias can be used to inject the search client into your services ## 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``` - -## Upgrade to 2.0.0 - -### BC-Breaks - -#### Interface changes -- Added `PermissionTypes $permissionType` parameter with default type `PermissionTypes::LIST` to -- `AssetSearchServiceInterface::search` method -- `DocumentSearchServiceInterface::search` method -- `DataObjectSearchServiceInterface::search` method -- `ElementSearchServiceInterface::search` method -- Search services `byId` methods now return elements based on the `PermissionTypes::VIEW` permission -- Added type specific interfaces for searches to avoid mixing up different search types in search services - - `AssetSearch` now implements `AssetSearchInterface` - - `DocumentSearch` now implements `DocumentSearchInterface` - - `ElementSearch` now implements `ElementSearchInterface` -- Search services now require the specific search type for the search - - `AssetSearchServiceInterface::search` now requires a `AssetSearchInterface` - - `DocumentSearchServiceInterface::search` now requires a `DocumentSearchInterface` - - `ElementSearchServiceInterface::search` now requires a `ElementSearchInterface` -- `SearchProviderInterface` now returns type specific search interfaces \ No newline at end of file + ```bin/console generic-data-index:update:index``` \ No newline at end of file diff --git a/src/Attribute/OpenSearch/AsSearchModifierHandler.php b/src/Attribute/OpenSearch/AsSearchModifierHandler.php deleted file mode 100644 index 49aa4a54..00000000 --- a/src/Attribute/OpenSearch/AsSearchModifierHandler.php +++ /dev/null @@ -1,28 +0,0 @@ -setArgument('$indexSettings', $indexSettings['index_settings']); $definition->setArgument('$searchSettings', $indexSettings['search_settings']); $definition->setArgument('$systemFieldsSettings', $indexSettings['system_fields_settings']); - if ($indexSettings['client_params']['client_type'] === ClientType::OPEN_SEARCH->value) { - $openSearchClientId = 'pimcore.open_search_client.' . $indexSettings['client_params']['client_name']; - $container->setAlias('generic-data-index.opensearch-client', $openSearchClientId) - ->setDeprecated( - 'pimcore/generic-data-index-bundle', - '1.3', - 'The "%alias_id%" service alias is deprecated and will be removed in version 2.0. ' . - 'Please use "generic-data-index.search-client" instead.' - ); - } + $clientId = $this->getDefaultSearchClientId($indexSettings); $container->setAlias('generic-data-index.search-client', $clientId); - $container->setParameter('generic-data-index.index-prefix', $indexSettings['client_params']['index_prefix']); + $container->setParameter( + 'generic-data-index.index-prefix', + $indexSettings['client_params']['index_prefix'] + ); $definition = $container->getDefinition(DispatchQueueMessagesHandler::class); $definition->setArgument('$queueSettings', $indexSettings['queue_settings']); diff --git a/src/Enum/SearchIndex/OpenSearch/AttributeType.php b/src/Enum/SearchIndex/OpenSearch/AttributeType.php deleted file mode 100644 index 0d19cef1..00000000 --- a/src/Enum/SearchIndex/OpenSearch/AttributeType.php +++ /dev/null @@ -1,36 +0,0 @@ -searchInformation; - } -} diff --git a/src/Model/OpenSearch/Aggregation/Aggregation.php b/src/Model/OpenSearch/Aggregation/Aggregation.php deleted file mode 100644 index 123b4dcf..00000000 --- a/src/Model/OpenSearch/Aggregation/Aggregation.php +++ /dev/null @@ -1,40 +0,0 @@ -name; - } - - public function getParams(): array - { - return $this->params; - } -} diff --git a/src/Model/OpenSearch/Aggregation/AggregationList.php b/src/Model/OpenSearch/Aggregation/AggregationList.php deleted file mode 100644 index efbeeb3b..00000000 --- a/src/Model/OpenSearch/Aggregation/AggregationList.php +++ /dev/null @@ -1,55 +0,0 @@ -aggregations[] = $aggregation; - } - - return $this; - } - - public function isEmpty(): bool - { - return empty($this->aggregations); - } - - public function toArray(): array - { - $result = []; - - foreach ($this->aggregations as $aggregation) { - $result[$aggregation->getName()] = $aggregation->getParams(); - } - - return $result; - } -} diff --git a/src/Model/OpenSearch/Debug/SearchInformation.php b/src/Model/OpenSearch/Debug/SearchInformation.php deleted file mode 100644 index a2304ead..00000000 --- a/src/Model/OpenSearch/Debug/SearchInformation.php +++ /dev/null @@ -1,86 +0,0 @@ -search; - } - - public function isSuccess(): bool - { - return $this->success; - } - - public function getResponse(): array - { - return $this->response; - } - - public function getExecutionTime(): int|float - { - return $this->executionTime; - } - - public function getStackTrace(): array - { - return $this->stackTrace; - } - - public function toArray(int $verbosity): array - { - $response = [ - 'success' => $this->success, - 'execution_time_ms' => $this->executionTime, - 'search' => $this->search->toArray(), - ]; - - if ($verbosity >= self::VERBOSITY_VERBOSE) { - $response['response'] = $this->response; - } - - if ($verbosity >= self::VERBOSITY_VERY_VERBOSE) { - $response['stackTrace'] = $this->stackTrace; - } - - return $response; - } -} diff --git a/src/Model/OpenSearch/Modifier/SearchModifierContext.php b/src/Model/OpenSearch/Modifier/SearchModifierContext.php deleted file mode 100644 index d08ed2ee..00000000 --- a/src/Model/OpenSearch/Modifier/SearchModifierContext.php +++ /dev/null @@ -1,43 +0,0 @@ -search; - } - - public function getOriginalSearch(): SearchInterface - { - return $this->originalSearch; - } -} diff --git a/src/Model/OpenSearch/Modifier/SearchModifierContextInterface.php b/src/Model/OpenSearch/Modifier/SearchModifierContextInterface.php deleted file mode 100644 index 13b25eb2..00000000 --- a/src/Model/OpenSearch/Modifier/SearchModifierContextInterface.php +++ /dev/null @@ -1,37 +0,0 @@ -toArray()); - } - - public function getParams(): array - { - return $this->params; - } - - public function addCondition(string $type, array $params): BoolQuery - { - $this->params[$type] = $this->params[$type] ?? []; - if (!empty($this->params[$type]) && !array_is_list($this->params[$type])) { - $this->params[$type] = [$this->params[$type]]; - } - if (array_is_list($params)) { - $this->params[$type] = array_merge($this->params[$type], $params); - } else { - $this->params[$type][] = $params; - } - - return $this; - } - - public function merge(BoolQuery $boolQuery): BoolQuery - { - foreach ($boolQuery->toArray() as $type => $params) { - $this->addCondition($type, $params); - } - - return $this; - } - - public function toArray(bool $withType = false): array - { - $result = $this->convertQueryObjectsToArray($this->getParams()); - $result = $this->simplifySingleTypes($result); - - if ($withType) { - return [$this->getType()->value => $result]; - } - - return $result; - } -} diff --git a/src/Model/OpenSearch/Query/DateFilter.php b/src/Model/OpenSearch/Query/DateFilter.php deleted file mode 100644 index 86ba113b..00000000 --- a/src/Model/OpenSearch/Query/DateFilter.php +++ /dev/null @@ -1,191 +0,0 @@ -startDate = is_int($startTimestamp) ? Carbon::createFromTimestamp($startTimestamp) : $startTimestamp; - $this->endDate = is_int($endTimestamp) ? Carbon::createFromTimestamp($endTimestamp) : $endTimestamp; - $this->onDate = is_int($onTimestamp) ? Carbon::createFromTimestamp($onTimestamp) : $onTimestamp; - } - - public static function createFromArray(string $field, array $params, bool $roundToDay = true): DateFilter - { - $allowedParams = [ - self::PARAM_END, - self::PARAM_START, - self::PARAM_ON, - ]; - - if (count(array_diff(array_keys($params), $allowedParams)) > 0) { - throw new InvalidArgumentException( - sprintf( - 'Invalid parameters for date filter (only %s are allowed): %s', - implode(', ', $allowedParams), - implode(', ', array_diff(array_keys($params), $allowedParams)) - ) - ); - } - - foreach ($params as $key => $value) { - if (!is_int($value)) { - throw new InvalidArgumentException( - sprintf( - 'Invalid value for parameter %s, expected integer, got %s', - $key, - gettype($value) - ) - ); - } - } - - return new self( - $field, - $params[self::PARAM_START] ?? null, - $params[self::PARAM_END] ?? null, - $params[self::PARAM_ON] ?? null, - $roundToDay - ); - } - - public function getType(): QueryType|string - { - return 'range'; - } - - public function isEmpty(): bool - { - return empty($this->getParams()); - } - - public function getParams(): array - { - $params = [ - 'format' => "yyyy-MM-dd'T'HH:mm:ssz", - ]; - if ($this->onDate) { - $params['gte'] = $this->getStartOfDay($this->onDate)->format(DateTimeInterface::ATOM); - $params['lte'] = $this->getEndOfDay($this->onDate)->format(DateTimeInterface::ATOM); - } else { - if ($this->startDate) { - $params['gte'] = $this->getStartOfDay($this->startDate)->format(DateTimeInterface::ATOM); - } - if ($this->endDate) { - $params['lte'] = $this->getEndOfDay($this->endDate)->format(DateTimeInterface::ATOM); - } - } - - return [ - $this->field => $params, - ]; - } - - public function toArray(bool $withType = false): array - { - if ($withType) { - return [$this->getType() => $this->getParams()]; - } - - return $this->getParams(); - } - - public function getField(): string - { - return $this->field; - } - - public function getEndTimestamp(): ?int - { - return $this->endDate->getTimestamp(); - } - - public function getStartTimestamp(): ?int - { - return $this->startDate->getTimestamp(); - } - - public function getOnTimestamp(): ?int - { - return $this->onDate->getTimestamp(); - } - - public function getEndDate(): Carbon - { - return $this->endDate; - } - - public function getStartDate(): Carbon - { - return $this->startDate; - } - - public function getOnDate(): Carbon - { - return $this->onDate; - } - - private function getStartOfDay(Carbon $date): Carbon - { - if (!$this->roundToDay) { - return $date; - } - - return $date->startOfDay(); - } - - private function getEndOfDay(Carbon $date): Carbon - { - if (!$this->roundToDay) { - return $date; - } - - return $date->endOfDay(); - } - - public function isRoundToDay(): bool - { - return $this->roundToDay; - } -} diff --git a/src/Model/OpenSearch/Query/Query.php b/src/Model/OpenSearch/Query/Query.php deleted file mode 100644 index 0985d27c..00000000 --- a/src/Model/OpenSearch/Query/Query.php +++ /dev/null @@ -1,58 +0,0 @@ -type; - } - - public function isEmpty(): bool - { - return empty($this->params); - } - - public function getParams(): array - { - return $this->params; - } - - public function toArray(bool $withType = false): array - { - if ($withType) { - return [$this->type => $this->getParams()]; - } - - return $this->getParams(); - } -} diff --git a/src/Model/OpenSearch/Query/QueryInterface.php b/src/Model/OpenSearch/Query/QueryInterface.php deleted file mode 100644 index 00b6df9a..00000000 --- a/src/Model/OpenSearch/Query/QueryInterface.php +++ /dev/null @@ -1,34 +0,0 @@ -isEmpty()) { - if ($this->boolQuery !== null) { - $this->boolQuery->merge($query); - - return $this; - } - $this->boolQuery = $query; - } - - if ($query !== null && !$query->isEmpty()) { - $this->queries[] = $query; - } - - return $this; - } - - public function isEmpty(): bool - { - return empty($this->queries); - } - - public function toArray(): array - { - $result = []; - - $this->combineToBoolQuery(); - - foreach ($this->queries as $query) { - $queryType = $query->getType() instanceof QueryType ? $query->getType()->value : $query->getType(); - $result[$queryType] = $result[$queryType] ?? []; - $result[$queryType][] = $query->toArray(); - } - - return $this->simplifySingleTypes($result); - } - - private function combineToBoolQuery(): void - { - if (count($this->queries) < 2) { - return; - } - - $this->boolQuery ??= new BoolQuery(); - - foreach ($this->queries as $query) { - if (!$query instanceof BoolQuery && !$query->isEmpty()) { - $this->boolQuery->addCondition(ConditionType::FILTER->value, $query->toArray(true)); - } - } - $this->queries = [$this->boolQuery]; - } -} diff --git a/src/Model/OpenSearch/Query/SimpleQueryStringFilter.php b/src/Model/OpenSearch/Query/SimpleQueryStringFilter.php deleted file mode 100644 index 2785f49b..00000000 --- a/src/Model/OpenSearch/Query/SimpleQueryStringFilter.php +++ /dev/null @@ -1,52 +0,0 @@ -value => [ - 'simple_query_string' => [ - 'query' => $this->term, - ], - ], - ]); - } - - public function getTerm(): string - { - return $this->term; - } - - public function toArrayAsSubQuery(): array - { - return [ - 'simple_query_string' => [ - 'query' => $this->term, - ], - ]; - } -} diff --git a/src/Model/OpenSearch/Query/TermFilter.php b/src/Model/OpenSearch/Query/TermFilter.php deleted file mode 100644 index f224e353..00000000 --- a/src/Model/OpenSearch/Query/TermFilter.php +++ /dev/null @@ -1,58 +0,0 @@ -value => [ - 'term' => [ - $this->field => $this->term, - ], - ], - ]); - } - - public function getField(): string - { - return $this->field; - } - - public function getTerm(): string|int|bool - { - return $this->term; - } - - public function toArrayAsSubQuery(): array - { - return [ - 'term' => [ - $this->field => $this->term, - ], - ]; - } -} diff --git a/src/Model/OpenSearch/Query/TermsFilter.php b/src/Model/OpenSearch/Query/TermsFilter.php deleted file mode 100644 index 650aff91..00000000 --- a/src/Model/OpenSearch/Query/TermsFilter.php +++ /dev/null @@ -1,60 +0,0 @@ -value => [ - 'terms' => [ - $this->field => $this->terms, - ], - ], - ]); - } - - public function getField(): string - { - return $this->field; - } - - /** @return (int|string)[] */ - public function getTerms(): array - { - return $this->terms; - } - - public function toArrayAsSubQuery(): array - { - return [ - 'terms' => [ - $this->field => $this->terms, - ], - ]; - } -} diff --git a/src/Model/OpenSearch/Query/WildcardFilter.php b/src/Model/OpenSearch/Query/WildcardFilter.php deleted file mode 100644 index 31a2d46f..00000000 --- a/src/Model/OpenSearch/Query/WildcardFilter.php +++ /dev/null @@ -1,82 +0,0 @@ -value => $this->getWildcardQueryArray(), - ]); - } - - public function getField(): string - { - return $this->field; - } - - public function getTerm(): string - { - return $this->term; - } - - public function isCaseInsensitive(): bool - { - return $this->caseInsensitive; - } - - public function toArrayAsSubQuery(): array - { - return $this->getWildcardQueryArray(); - } - - private function getWildcardQueryArray(): array - { - $term = $this->term; - - if ($term !== '' && !str_contains($term, '*')) { - if ($this->defaultWildcardMode === WildcardFilterMode::BOTH) { - $term = "*$term*"; - } elseif ($this->defaultWildcardMode === WildcardFilterMode::PREFIX) { - $term = "*$term"; - } elseif ($this->defaultWildcardMode === WildcardFilterMode::SUFFIX) { - $term = "$term*"; - } - } - - return [ - 'wildcard' => [ - $this->field => [ - 'value' => $term, - 'case_insensitive' => $this->caseInsensitive, - ], - ], - ]; - } -} diff --git a/src/Model/OpenSearch/Search.php b/src/Model/OpenSearch/Search.php deleted file mode 100644 index 32982c68..00000000 --- a/src/Model/OpenSearch/Search.php +++ /dev/null @@ -1,175 +0,0 @@ -from; - } - - public function setFrom(?int $from): OpenSearchSearchInterface - { - $this->from = $from; - - return $this; - } - - public function getSize(): ?int - { - return $this->size; - } - - public function setSize(?int $size): OpenSearchSearchInterface - { - $this->size = $size; - - return $this; - } - - public function getSource(): bool|array|string|null - { - return $this->source; - } - - public function setSource(bool|array|string|null $source): OpenSearchSearchInterface - { - $this->source = $source; - - return $this; - } - - public function addQuery(QueryInterface $query = null): OpenSearchSearchInterface - { - $this->queryList->addQuery($query); - - return $this; - } - - public function addSort(FieldSort $sort): OpenSearchSearchInterface - { - $this->sortList->addSort($sort); - - return $this; - } - - public function addAggregation(Aggregation $aggregation): OpenSearchSearchInterface - { - $this->aggregationList->addAggregation($aggregation); - - return $this; - } - - public function getQueryList(): QueryList - { - return $this->queryList; - } - - public function getSortList(): FieldSortList - { - return $this->sortList; - } - - public function setSortList(FieldSortList $sortList): OpenSearchSearchInterface - { - $this->sortList = $sortList; - - return $this; - } - - public function isReverseItemOrder(): bool - { - return $this->reverseItemOrder; - } - - public function setReverseItemOrder(bool $reverseItemOrder): OpenSearchSearchInterface - { - $this->reverseItemOrder = $reverseItemOrder; - - return $this; - } - - public function getSearchAfter(): ?array - { - return $this->searchAfter; - } - - public function setSearchAfter(?array $searchAfter): OpenSearchSearchInterface - { - $this->searchAfter = is_array($searchAfter) && !empty($searchAfter) ? $searchAfter : null; - - return $this; - } - - public function toArray(): array - { - $result = [ - 'from' => $this->getSearchAfter() !== null ? null : $this->from, - 'size' => $this->size, - '_source' => $this->source, - ]; - - foreach ($result as $key => $value) { - if ($value === null) { - unset($result[$key]); - } - } - - if (!$this->queryList->isEmpty()) { - $result['query'] = $this->queryList->toArray(); - } - - if (!$this->aggregationList->isEmpty()) { - $result['aggs'] = $this->aggregationList->toArray(); - } - - if (!$this->sortList->isEmpty()) { - $result['sort'] = $this->sortList->toArray(); - } - - if ($this->getSearchAfter() !== null) { - $result['search_after'] = $this->getSearchAfter(); - } - - return $result; - } -} diff --git a/src/Model/OpenSearch/Sort/FieldSort.php b/src/Model/OpenSearch/Sort/FieldSort.php deleted file mode 100644 index 22f60b6d..00000000 --- a/src/Model/OpenSearch/Sort/FieldSort.php +++ /dev/null @@ -1,82 +0,0 @@ -field; - } - - public function setField(string $field): FieldSort - { - $this->field = $field; - - return $this; - } - - public function getOrder(): string - { - return $this->order; - } - - public function setOrder(?string $order): FieldSort - { - $this->order = $order; - - return $this; - } - - public function getParams(): array - { - return $this->params; - } - - public function setParams(array $params): FieldSort - { - $this->params = $params; - - return $this; - } - - public function toArray(): array - { - if ($this->order) { - $this->params['order'] = $this->order; - } - - return [ - $this->field => $this->params, - ]; - } -} diff --git a/src/Model/OpenSearch/Sort/FieldSortList.php b/src/Model/OpenSearch/Sort/FieldSortList.php deleted file mode 100644 index d9ee20eb..00000000 --- a/src/Model/OpenSearch/Sort/FieldSortList.php +++ /dev/null @@ -1,60 +0,0 @@ -sort[] = $sort; - } - - return $this; - } - - public function getSort(): array - { - return $this->sort; - } - - public function isEmpty(): bool - { - return empty($this->sort); - } - - public function toArray(): array - { - $result = []; - - foreach ($this->sort as $sort) { - $result[] = $sort->toArray(); - } - - return count($result) === 1 ? reset($result) : $result; - } -} diff --git a/src/Model/OpenSearch/Traits/QueryObjectsToArrayTrait.php b/src/Model/OpenSearch/Traits/QueryObjectsToArrayTrait.php deleted file mode 100644 index e742c29c..00000000 --- a/src/Model/OpenSearch/Traits/QueryObjectsToArrayTrait.php +++ /dev/null @@ -1,43 +0,0 @@ -toArrayAsSubQuery(); - } elseif ($value instanceof QueryInterface) { - $value = $value->toArray(true); - } - } - ); - - return $params; - } -} diff --git a/src/Model/OpenSearch/Traits/SimplifySingleTypesTrait.php b/src/Model/OpenSearch/Traits/SimplifySingleTypesTrait.php deleted file mode 100644 index 5f2df569..00000000 --- a/src/Model/OpenSearch/Traits/SimplifySingleTypesTrait.php +++ /dev/null @@ -1,35 +0,0 @@ - $items) { - if (array_is_list($items) && count($items) === 1) { - $queries[$queryType] = reset($items); - } - } - - return $queries; - } -} diff --git a/src/SearchIndexAdapter/OpenSearch/Asset/FieldDefinitionAdapter/AbstractAdapter.php b/src/SearchIndexAdapter/OpenSearch/Asset/FieldDefinitionAdapter/AbstractAdapter.php deleted file mode 100644 index ec05f409..00000000 --- a/src/SearchIndexAdapter/OpenSearch/Asset/FieldDefinitionAdapter/AbstractAdapter.php +++ /dev/null @@ -1,149 +0,0 @@ -type = $type; - - return $this; - } - - public function getType(): string - { - return $this->type; - } - - abstract public function getIndexMapping(): array; - - public function normalize(mixed $value): mixed - { - return $value; - } - - /** - * @param OpenSearchSearchInterface $adapterSearch - * - * @throws InvalidArgumentException - */ - public function applySearchFilter(AssetMetaDataFilter $filter, AdapterSearchInterface $adapterSearch): void - { - if ($filter->getType() !== $this->getType()) { - throw new InvalidArgumentException( - sprintf( - '%s does not support filter type "%s" for filter "%s"', - static::class, - $filter->getType(), - $filter->getName() - ) - ); - } - - $value = $filter->getData(); - - $query = null; - if ($this->isValidScalar($value)) { - $query = new TermFilter($this->getSearchFilterFieldPath($filter), $value); - } elseif (is_array($value)) { - try { - $this->validateArray($value); - } catch (ValueError) { - $this->throwInvalidFilterValueArgumentException($value, $filter); - } - $value = array_unique($value); - $query = new TermsFilter($this->getSearchFilterFieldPath($filter), $value); - } - - if ($query === null) { - $this->throwInvalidFilterValueArgumentException($value, $filter); - } - - $adapterSearch->addQuery( - $query - ); - } - - public function getSearchFilterAggregation(AssetMetaDataAggregation $aggregation): ?Aggregation - { - return null; - } - - protected function isValidScalar(mixed $value): bool - { - return is_string($value); - } - - /** - * @throws ValueError - */ - protected function validateArray(array $value): void - { - new ArrayOfStrings($value); - } - - protected function getSearchFilterFieldPath(AssetMetaDataFilter|AssetMetaDataAggregation $filter): string - { - return implode('.', [ - FieldCategory::STANDARD_FIELDS->value, - $filter->getName(), - $filter->getLanguage() ?? MappingProperty::NOT_LOCALIZED_KEY, - ]); - } - - /** - * @throws InvalidArgumentException - */ - protected function throwInvalidFilterValueArgumentException(mixed $value, AssetMetaDataFilter $filter): void - { - throw new InvalidArgumentException( - sprintf( - 'Unsupported value type "%s" for filter "%s"', - gettype($value), - $filter->getName() - ) - ); - } -} diff --git a/src/SearchIndexAdapter/OpenSearch/DataObject/FieldDefinitionAdapter/AbstractAdapter.php b/src/SearchIndexAdapter/OpenSearch/DataObject/FieldDefinitionAdapter/AbstractAdapter.php deleted file mode 100644 index 2fa7cf10..00000000 --- a/src/SearchIndexAdapter/OpenSearch/DataObject/FieldDefinitionAdapter/AbstractAdapter.php +++ /dev/null @@ -1,107 +0,0 @@ -fieldDefinition = $fieldDefinition; - - return $this; - } - - public function getFieldDefinition(): Data - { - return $this->fieldDefinition; - } - - public function getIndexAttributeName(): string - { - return $this->fieldDefinition->getName(); - } - - public function getFieldDefinitionService(): FieldDefinitionServiceInterface - { - return $this->fieldDefinitionService; - } - - public function normalize(mixed $value): mixed - { - if ($this->fieldDefinition instanceof NormalizerInterface) { - return $this->fieldDefinition->normalize($value); - } - - return $value; - } - - /** - * @throws Exception - */ - public function getInheritedData( - Concrete $dataObject, - int $objectId, - mixed $value, - string $key, - ?string $language = null, - callable $callback = null - ): array { - if (!$this->fieldDefinition->isEmpty($value)) { - return []; - } - - $path = $key; - if ($language !== null) { - $path .= '.' . $language; - } - - $parent = $dataObject->getNextParentForInheritance(); - if ($parent === null) { - return $objectId === $dataObject->getId() ? [] : [$path => ['originId' => $dataObject->getId()]]; - } - - $parentValue = $callback ? $callback($parent, $key, $language) : $parent->get($key, $language); - if (!$this->fieldDefinition->isEmpty($parentValue)) { - return [$path => ['originId' => $parent->getId()]]; - } - - return $this->getInheritedData($parent, $objectId, $value, $key, $language, $callback); - } -} diff --git a/src/autoload.php b/src/autoload.php deleted file mode 100644 index 8fef290e..00000000 --- a/src/autoload.php +++ /dev/null @@ -1,120 +0,0 @@ - OpenSearchAttributeType::class, - ConditionType::class => OpenSearchConditionType::class, - QueryType::class => OpenSearchQueryType::class, - WildcardFilterMode::class => OpenSearchWildcardFilterMode::class, - SearchFailedException::class => OpenSearchSearchFailedException::class, - Aggregation::class => OpenSearchAggregation::class, - AggregationList::class => OpenSearchAggregationList::class, - SearchInformation::class => OpenSearchSearchInformation::class, - SearchModifierContext::class => OpenSearchModifierContext::class, - SearchModifierContextInterface::class => OpenSearchModifierContextInterface::class, - AsSubQueryInterface::class => OpenSearchAsSubQueryInterface::class, - BoolQuery::class => OpenSearchBoolQuery::class, - DateFilter::class => OpenSearchDateFilter::class, - Query::class => OpenSearchQuery::class, - QueryInterface::class => OpenSearchQueryInterface::class, - QueryList::class => OpenSearchQueryList::class, - SimpleQueryStringFilter::class => OpenSearchSimpleQueryStringFilter::class, - TermFilter::class => OpenSearchTermFilter::class, - TermsFilter::class => OpenSearchTermsFilter::class, - WildcardFilter::class => OpenSearchWildcardFilter::class, - FieldSort::class => OpenSearchFieldSort::class, - FieldSortList::class => OpenSearchFieldSortList::class, - QueryObjectsToArrayTrait::class => OpenSearchQueryObjectsToArrayTrait::class, - SimplifySingleTypesTrait::class => OpenSearchSimplifySingleTypesTrait::class, - Search::class => OpenSearchSearch::class, - DefaultSearchInterface::class => OpenSearchSearchInterface::class, - AssetAbstractAdapter::class => OpenSearchAssetAbstractAdapter::class, - DataObjectAbstractAdapter::class => OpenSearchDataObjectAbstractAdapter::class, - BooleanAdapter::class => ASSET_FIELD_DEFINITION_ADAPTER_NAMESPACE . 'BooleanAdapter', - DateAdapter::class => ASSET_FIELD_DEFINITION_ADAPTER_NAMESPACE . 'DateAdapter', - KeywordAdapter::class => ASSET_FIELD_DEFINITION_ADAPTER_NAMESPACE . 'KeywordAdapter', - RelationAdapter::class => ASSET_FIELD_DEFINITION_ADAPTER_NAMESPACE . 'RelationAdapter', - TextKeywordAdapter::class => ASSET_FIELD_DEFINITION_ADAPTER_NAMESPACE . 'TextKeywordAdapter', -]; - -foreach ($classesToAlias as $originalClass => $aliasClass) { - class_alias($originalClass, $aliasClass); -}