|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @copyright Copyright (C) Ibexa AS. All rights reserved. |
| 5 | + * @license For full copyright and license information view LICENSE file distributed with this source code. |
| 6 | + */ |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Ibexa\Contracts\Core\Repository\Values\Content; |
| 10 | + |
| 11 | +use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; |
| 12 | +use Ibexa\Contracts\Core\Repository\Values\Content\Query\Embedding; |
| 13 | +use InvalidArgumentException; |
| 14 | + |
| 15 | +/** |
| 16 | + * This class is used to perform an embedding query. |
| 17 | + */ |
| 18 | +class EmbeddingQuery extends Query |
| 19 | +{ |
| 20 | + private ?Embedding $embedding = null; |
| 21 | + |
| 22 | + public function getEmbedding(): ?Embedding |
| 23 | + { |
| 24 | + return $this->embedding; |
| 25 | + } |
| 26 | + |
| 27 | + public function setEmbedding(?Embedding $embedding): void |
| 28 | + { |
| 29 | + $this->embedding = $embedding; |
| 30 | + } |
| 31 | + |
| 32 | + public function getFilter(): ?Criterion |
| 33 | + { |
| 34 | + return $this->filter; |
| 35 | + } |
| 36 | + |
| 37 | + public function setFilter(Criterion $filter): void |
| 38 | + { |
| 39 | + $this->filter = $filter; |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @return \Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation[] |
| 44 | + */ |
| 45 | + public function getAggregations(): array |
| 46 | + { |
| 47 | + return $this->aggregations; |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @param \Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation[] $aggregations |
| 52 | + */ |
| 53 | + public function setAggregations(array $aggregations): void |
| 54 | + { |
| 55 | + $this->aggregations = $aggregations; |
| 56 | + } |
| 57 | + |
| 58 | + public function getOffset(): int |
| 59 | + { |
| 60 | + return $this->offset; |
| 61 | + } |
| 62 | + |
| 63 | + public function setOffset(int $offset): void |
| 64 | + { |
| 65 | + $this->offset = $offset; |
| 66 | + } |
| 67 | + |
| 68 | + public function getLimit(): int |
| 69 | + { |
| 70 | + return $this->limit; |
| 71 | + } |
| 72 | + |
| 73 | + public function setLimit(int $limit): void |
| 74 | + { |
| 75 | + $this->limit = $limit; |
| 76 | + } |
| 77 | + |
| 78 | + public function setPerformCount(bool $performCount): void |
| 79 | + { |
| 80 | + $this->performCount = $performCount; |
| 81 | + } |
| 82 | + |
| 83 | + public function getPerformCount(): bool |
| 84 | + { |
| 85 | + return $this->performCount; |
| 86 | + } |
| 87 | + |
| 88 | + public function isValid(): bool |
| 89 | + { |
| 90 | + $invalid = []; |
| 91 | + |
| 92 | + if ($this->query !== null) { |
| 93 | + $invalid[] = 'query'; |
| 94 | + } |
| 95 | + if (!empty($this->sortClauses)) { |
| 96 | + $invalid[] = 'sortClauses'; |
| 97 | + } |
| 98 | + if (!empty($this->facetBuilders)) { |
| 99 | + $invalid[] = 'facetBuilders'; |
| 100 | + } |
| 101 | + if ($this->spellcheck !== null) { |
| 102 | + $invalid[] = 'spellcheck'; |
| 103 | + } |
| 104 | + |
| 105 | + if (count($invalid) > 0) { |
| 106 | + throw new InvalidArgumentException( |
| 107 | + sprintf( |
| 108 | + 'EmbeddingQuery may not set [%s].', |
| 109 | + implode(', ', $invalid) |
| 110 | + ) |
| 111 | + ); |
| 112 | + } |
| 113 | + |
| 114 | + return true; |
| 115 | + } |
| 116 | +} |
0 commit comments