From ae29226d73ca98657875552568fff2a2daa06222 Mon Sep 17 00:00:00 2001 From: Pavel Piligrimov Date: Fri, 13 Jan 2023 11:14:28 +0500 Subject: [PATCH] added criteria, updated logic --- composer.json | 2 +- src/Search/Criteria.php | 35 ++++++ src/Search/Document/Document.php | 15 --- src/Search/Document/DocumentCollection.php | 20 --- src/Search/Document/Product.php | 21 ++++ src/Search/Document/ProductCollection.php | 17 +++ src/Search/Document/Property/AttrType.php | 30 +++++ src/Search/Document/Property/PropertyType.php | 40 ++++++ src/Search/Document/Property/Type.php | 13 ++ src/Search/Facet/Facet.php | 31 ++--- src/Search/Facet/FacetCollection.php | 3 +- src/Search/Facet/FacetItemCollection.php | 13 -- src/Search/Facet/FacetItemList.php | 31 ----- src/Search/Facet/FacetItemRange.php | 51 -------- src/Search/Facet/FacetItemType.php | 62 ---------- src/Search/Facet/FacetType.php | 13 -- src/Search/Facet/Item/FacetItem.php | 39 ++++++ src/Search/Facet/Item/FacetItemCollection.php | 14 +++ src/Search/Facet/Item/FacetItemList.php | 24 ++++ src/Search/Facet/Item/FacetItemRange.php | 55 +++++++++ src/Search/Facet/Item/FacetItemRangeDTO.php | 22 ++++ src/Search/Facet/Item/FacetItemSingle.php | 18 +++ src/Search/Facet/ListFacetType.php | 8 -- src/Search/Facet/RangeFacetType.php | 8 -- src/Search/Facet/Type/FacetListType.php | 7 ++ src/Search/Facet/Type/FacetRangeType.php | 7 ++ src/Search/Facet/Type/FacetType.php | 7 ++ src/Search/Filter/Field.php | 18 +++ src/Search/Filter/Filter.php | 35 +++++- src/Search/Filter/FilterCategory.php | 22 ---- src/Search/Filter/FilterCollection.php | 4 + src/Search/Filter/FilterKeyword.php | 21 ++-- src/Search/Filter/FilterNumber.php | 25 ++-- src/Search/Filter/FilterOperator.php | 48 ++++++++ src/Search/Filter/FilterValue.php | 8 ++ src/Search/Order/Order.php | 34 ++++++ src/Search/Order/OrderAscType.php | 8 ++ src/Search/Order/OrderCollection.php | 14 +++ src/Search/Order/OrderDescType.php | 8 ++ src/Search/Order/OrderType.php | 13 ++ src/Search/Pagination.php | 6 +- src/Search/Query.php | 14 --- src/Search/Query/SearchQuery.php | 15 +++ src/Search/Query/SearchQueryHandler.php | 22 ++++ src/Search/Query/SearchQueryResponse.php | 15 +++ src/Search/Result.php | 31 ++++- src/Search/SearchQuery/SearchQuery.php | 114 ------------------ src/Search/SearchQuery/SearchQueryHandler.php | 71 ----------- src/Search/SearchQuery/SearchResult.php | 21 ---- src/Search/SearchService.php | 9 +- src/Search/Sorting/Sorting.php | 8 -- src/Search/Sorting/SortingCollection.php | 13 -- src/Search/Sorting/SortingFieldPair.php | 8 -- src/Search/Sorting/SortingPair.php | 20 --- .../Sorting/SortingPropertyKeywordPair.php | 8 -- .../Sorting/SortingPropertyNumberPair.php | 8 -- 56 files changed, 655 insertions(+), 592 deletions(-) create mode 100644 src/Search/Criteria.php delete mode 100644 src/Search/Document/Document.php delete mode 100644 src/Search/Document/DocumentCollection.php create mode 100644 src/Search/Document/Product.php create mode 100644 src/Search/Document/ProductCollection.php create mode 100644 src/Search/Document/Property/AttrType.php create mode 100644 src/Search/Document/Property/PropertyType.php create mode 100644 src/Search/Document/Property/Type.php delete mode 100644 src/Search/Facet/FacetItemCollection.php delete mode 100644 src/Search/Facet/FacetItemList.php delete mode 100644 src/Search/Facet/FacetItemRange.php delete mode 100644 src/Search/Facet/FacetItemType.php delete mode 100644 src/Search/Facet/FacetType.php create mode 100644 src/Search/Facet/Item/FacetItem.php create mode 100644 src/Search/Facet/Item/FacetItemCollection.php create mode 100644 src/Search/Facet/Item/FacetItemList.php create mode 100644 src/Search/Facet/Item/FacetItemRange.php create mode 100644 src/Search/Facet/Item/FacetItemRangeDTO.php create mode 100644 src/Search/Facet/Item/FacetItemSingle.php delete mode 100644 src/Search/Facet/ListFacetType.php delete mode 100644 src/Search/Facet/RangeFacetType.php create mode 100644 src/Search/Facet/Type/FacetListType.php create mode 100644 src/Search/Facet/Type/FacetRangeType.php create mode 100644 src/Search/Facet/Type/FacetType.php create mode 100644 src/Search/Filter/Field.php delete mode 100644 src/Search/Filter/FilterCategory.php create mode 100644 src/Search/Filter/FilterOperator.php create mode 100644 src/Search/Filter/FilterValue.php create mode 100644 src/Search/Order/Order.php create mode 100644 src/Search/Order/OrderAscType.php create mode 100644 src/Search/Order/OrderCollection.php create mode 100644 src/Search/Order/OrderDescType.php create mode 100644 src/Search/Order/OrderType.php delete mode 100644 src/Search/Query.php create mode 100644 src/Search/Query/SearchQuery.php create mode 100644 src/Search/Query/SearchQueryHandler.php create mode 100644 src/Search/Query/SearchQueryResponse.php delete mode 100644 src/Search/SearchQuery/SearchQuery.php delete mode 100644 src/Search/SearchQuery/SearchQueryHandler.php delete mode 100644 src/Search/SearchQuery/SearchResult.php delete mode 100644 src/Search/Sorting/Sorting.php delete mode 100644 src/Search/Sorting/SortingCollection.php delete mode 100644 src/Search/Sorting/SortingFieldPair.php delete mode 100644 src/Search/Sorting/SortingPair.php delete mode 100644 src/Search/Sorting/SortingPropertyKeywordPair.php delete mode 100644 src/Search/Sorting/SortingPropertyNumberPair.php diff --git a/composer.json b/composer.json index d887c77..b578e95 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "email": "p.piligrimov@iqdev.digital" } ], - "version": "0.0.1", + "version": "0.1.0", "type": "library", "keywords": [ "search", diff --git a/src/Search/Criteria.php b/src/Search/Criteria.php new file mode 100644 index 0000000..b2b6c4c --- /dev/null +++ b/src/Search/Criteria.php @@ -0,0 +1,35 @@ +filters = new FilterCollection(); + $this->sorting = new OrderCollection(); + $this->pagination = new Pagination(); + } + + public function filters(): FilterCollection + { + return $this->filters; + } + + public function sorting(): OrderCollection + { + return $this->sorting; + } + + public function pagination(): Pagination + { + return $this->pagination; + } +} diff --git a/src/Search/Document/Document.php b/src/Search/Document/Document.php deleted file mode 100644 index 1588622..0000000 --- a/src/Search/Document/Document.php +++ /dev/null @@ -1,15 +0,0 @@ -id = $id; - $this->data = $data; - } -} diff --git a/src/Search/Document/DocumentCollection.php b/src/Search/Document/DocumentCollection.php deleted file mode 100644 index d232f40..0000000 --- a/src/Search/Document/DocumentCollection.php +++ /dev/null @@ -1,20 +0,0 @@ - - * @implements CollectionInterface - */ -final class DocumentCollection extends AbstractCollection -{ - public function getType(): string - { - return Document::class; - } -} \ No newline at end of file diff --git a/src/Search/Document/Product.php b/src/Search/Document/Product.php new file mode 100644 index 0000000..9fa2ca7 --- /dev/null +++ b/src/Search/Document/Product.php @@ -0,0 +1,21 @@ +id = $id; + $this->title = $title; + $this->info = $info; + } +} diff --git a/src/Search/Document/ProductCollection.php b/src/Search/Document/ProductCollection.php new file mode 100644 index 0000000..0c8abda --- /dev/null +++ b/src/Search/Document/ProductCollection.php @@ -0,0 +1,17 @@ + + */ +final class ProductCollection extends AbstractCollection +{ + + public function getType(): string + { + return Product::class; + } +} diff --git a/src/Search/Document/Property/AttrType.php b/src/Search/Document/Property/AttrType.php new file mode 100644 index 0000000..f7e2ea8 --- /dev/null +++ b/src/Search/Document/Property/AttrType.php @@ -0,0 +1,30 @@ +key = $key; + $this->type = $type; + } + + public function key(): string + { + return $this->key; + } + + public function type(): ?string + { + return $this->type; + } + + public static function types(): array + { + return []; + } +} \ No newline at end of file diff --git a/src/Search/Document/Property/PropertyType.php b/src/Search/Document/Property/PropertyType.php new file mode 100644 index 0000000..fd16ec8 --- /dev/null +++ b/src/Search/Document/Property/PropertyType.php @@ -0,0 +1,40 @@ +key = $key; + $this->type = $type; + } + + public function key(): string + { + return $this->key; + } + + public function type(): string + { + return $this->type; + } + + public static function types(): array + { + return [ + self::TYPE_NUMBER, + self::TYPE_KEYWORD, + ]; + } +} diff --git a/src/Search/Document/Property/Type.php b/src/Search/Document/Property/Type.php new file mode 100644 index 0000000..3817a08 --- /dev/null +++ b/src/Search/Document/Property/Type.php @@ -0,0 +1,13 @@ +type = $type; - $this->code = $code; - $this->items = new FacetItemCollection(); - } + protected FacetType $type; + + protected string $code; - public function getLabel(): ?string + public function __construct(FacetType $type, string $code) { - return $this->label; + $this->type = $type; + $this->code = $code; + $this->products = new FacetItemCollection(); } public function getType(): FacetType @@ -31,9 +29,4 @@ final class Facet { return $this->code; } - - public function getPosition(): int - { - return $this->position; - } -} \ No newline at end of file +} diff --git a/src/Search/Facet/FacetCollection.php b/src/Search/Facet/FacetCollection.php index 51c42f9..3a5f5a8 100644 --- a/src/Search/Facet/FacetCollection.php +++ b/src/Search/Facet/FacetCollection.php @@ -6,8 +6,9 @@ use Ramsey\Collection\AbstractCollection; final class FacetCollection extends AbstractCollection { + public function getType(): string { return Facet::class; } -} \ No newline at end of file +} diff --git a/src/Search/Facet/FacetItemCollection.php b/src/Search/Facet/FacetItemCollection.php deleted file mode 100644 index d6f5388..0000000 --- a/src/Search/Facet/FacetItemCollection.php +++ /dev/null @@ -1,13 +0,0 @@ -value; - } - - /** - * @param string $value - * @param int $count - * - * @return static - */ - public static function createFromValue(string $value, int $count): self - { - $instance = new self(); - $instance->count = $count; - $instance->value = $value; - - return $instance; - } -} \ No newline at end of file diff --git a/src/Search/Facet/FacetItemRange.php b/src/Search/Facet/FacetItemRange.php deleted file mode 100644 index 72f090e..0000000 --- a/src/Search/Facet/FacetItemRange.php +++ /dev/null @@ -1,51 +0,0 @@ - $this->min, - 'max' => $this->max - ]; - } - - /** - * @return array - */ - public function getSelectedRange(): array - { - return [ - 'min' => $this->selectedMin, - 'max' => $this->selectedMax - ]; - } - - public static function createFromRange( - ?float $min, - ?float $max, - int $count, - ?float $selectedMin = null, - ?float $selectedMax = null - ): self { - $instance = new self(); - - $instance->count = $count; - - $instance->min = $min; - $instance->max = $max; - $instance->selectedMin = $selectedMin; - $instance->selectedMax = $selectedMax; - - return $instance; - } -} \ No newline at end of file diff --git a/src/Search/Facet/FacetItemType.php b/src/Search/Facet/FacetItemType.php deleted file mode 100644 index 34f9738..0000000 --- a/src/Search/Facet/FacetItemType.php +++ /dev/null @@ -1,62 +0,0 @@ -count; - } - - /** - * @param string|null $sLabel - * - * @return self - */ - public function setLabel(?string $sLabel): self - { - $this->label = $sLabel; - return $this; - } - - /** - * @return string|null - */ - public function getLabel(): ?string - { - return $this->label; - } - - /** - * @return bool - */ - public function isActive(): bool - { - return $this->count > 0; - } - - /** - * @return $this - */ - protected function setSelected(bool $selected): self - { - $this->selected = $selected; - return $this; - } - - /** - * @return bool - */ - public function isSelected(): bool - { - return $this->selected; - } -} \ No newline at end of file diff --git a/src/Search/Facet/FacetType.php b/src/Search/Facet/FacetType.php deleted file mode 100644 index d879c07..0000000 --- a/src/Search/Facet/FacetType.php +++ /dev/null @@ -1,13 +0,0 @@ -label; + } + + public function getValue(): ?string + { + return $this->value; + } + + public function getCount(): int + { + return $this->count; + } + + public function isActive(): bool + { + return $this->count > 0; + } + + public function isSelected(): bool + { + return $this->selected; + } +} diff --git a/src/Search/Facet/Item/FacetItemCollection.php b/src/Search/Facet/Item/FacetItemCollection.php new file mode 100644 index 0000000..a786e5e --- /dev/null +++ b/src/Search/Facet/Item/FacetItemCollection.php @@ -0,0 +1,14 @@ +value = $value; + $instance->label = $label; + $instance->count = $count; + $instance->selected = $selected; + + return $instance; + } +} diff --git a/src/Search/Facet/Item/FacetItemRange.php b/src/Search/Facet/Item/FacetItemRange.php new file mode 100644 index 0000000..ceb485c --- /dev/null +++ b/src/Search/Facet/Item/FacetItemRange.php @@ -0,0 +1,55 @@ +label = $label; + $instance->count = $count; + $instance->selected = $selected; + + $instance->data = $data; + $instance->selectedData = $selectedData; + + return $instance; + } + + public function getFullRange(): array + { + return [ + 'min' => $this->data->min, + 'max' => $this->data->max + ]; + } + + public function getSelectedRange(): array + { + return [ + 'min' => $this->selectedData->min, + 'max' => $this->selectedData->max + ]; + } + + public function getData(): FacetItemRangeDTO + { + return $this->data; + } + + public function getSelectedData(): FacetItemRangeDTO + { + return $this->selectedData; + } +} diff --git a/src/Search/Facet/Item/FacetItemRangeDTO.php b/src/Search/Facet/Item/FacetItemRangeDTO.php new file mode 100644 index 0000000..fe889f9 --- /dev/null +++ b/src/Search/Facet/Item/FacetItemRangeDTO.php @@ -0,0 +1,22 @@ +min = $min; + $instance->max = $max; + $instance->avg = $avg; + $instance->sum = $sum; + + return $instance; + } +} \ No newline at end of file diff --git a/src/Search/Facet/Item/FacetItemSingle.php b/src/Search/Facet/Item/FacetItemSingle.php new file mode 100644 index 0000000..c949d9d --- /dev/null +++ b/src/Search/Facet/Item/FacetItemSingle.php @@ -0,0 +1,18 @@ +value = $value; + $instance->count = $count; + $instance->label = $label; + + return $instance; + } +} diff --git a/src/Search/Facet/ListFacetType.php b/src/Search/Facet/ListFacetType.php deleted file mode 100644 index 1a22ce4..0000000 --- a/src/Search/Facet/ListFacetType.php +++ /dev/null @@ -1,8 +0,0 @@ -value = $value; + } + + public function value(): string + { + return $this->value; + } +} diff --git a/src/Search/Filter/Filter.php b/src/Search/Filter/Filter.php index 6d3e4bf..2ea2e66 100644 --- a/src/Search/Filter/Filter.php +++ b/src/Search/Filter/Filter.php @@ -2,6 +2,35 @@ namespace IQDEV\Search\Filter; -interface Filter { - public function key(): string; -} \ No newline at end of file +final class Filter +{ + private Field $field; + private FilterOperator $operator; + private FilterValue $value; + + public function __construct( + Field $field, + FilterOperator $operator, + FilterValue $value + ) + { + $this->field = $field; + $this->operator = $operator; + $this->value = $value; + } + + public function field(): Field + { + return $this->field; + } + + public function operator(): FilterOperator + { + return $this->operator; + } + + public function value(): FilterValue + { + return $this->value; + } +} diff --git a/src/Search/Filter/FilterCategory.php b/src/Search/Filter/FilterCategory.php deleted file mode 100644 index 50e02c3..0000000 --- a/src/Search/Filter/FilterCategory.php +++ /dev/null @@ -1,22 +0,0 @@ -value = $value; - } - - public function key(): string - { - return 'category_id'; - } -} diff --git a/src/Search/Filter/FilterCollection.php b/src/Search/Filter/FilterCollection.php index f3b691b..c6849a4 100644 --- a/src/Search/Filter/FilterCollection.php +++ b/src/Search/Filter/FilterCollection.php @@ -6,6 +6,10 @@ use Ramsey\Collection\AbstractCollection; class FilterCollection extends AbstractCollection { + + /** + * @inheritDoc + */ public function getType(): string { return Filter::class; diff --git a/src/Search/Filter/FilterKeyword.php b/src/Search/Filter/FilterKeyword.php index f119a7e..40b75e5 100644 --- a/src/Search/Filter/FilterKeyword.php +++ b/src/Search/Filter/FilterKeyword.php @@ -2,27 +2,24 @@ namespace IQDEV\Search\Filter; -class FilterKeyword implements Filter +class FilterKeyword implements FilterValue { - public string $key; /** @var string|string[] */ public $value; - + /** - * @param string $key - * @param string|array $value + * @param string|string[] $value */ - public function __construct( - string $key, - $value - ) + public function __construct($value) { - $this->key = $key; $this->value = $value; } - public function key(): string + /** + * @return string|string[] + */ + public function value() { - return $this->key; + return $this->value; } } diff --git a/src/Search/Filter/FilterNumber.php b/src/Search/Filter/FilterNumber.php index 0ec7cda..7156464 100644 --- a/src/Search/Filter/FilterNumber.php +++ b/src/Search/Filter/FilterNumber.php @@ -2,31 +2,22 @@ namespace IQDEV\Search\Filter; -class FilterNumber implements Filter +class FilterNumber implements FilterValue { - public string $key; - public float $min; - public float $max; - + public float $value; + /** - * @param string $key - * @param float $min - * @param float $max + * @param float $value */ public function __construct( - string $key, - float $min = 0, - float $max = PHP_INT_MAX + float $value ) { - $this->key = $key; - $this->min = $min; - $this->max = $max; + $this->value = $value; } - public function key(): string + public function value(): float { - return $this->key; + return $this->value; } - } diff --git a/src/Search/Filter/FilterOperator.php b/src/Search/Filter/FilterOperator.php new file mode 100644 index 0000000..cfff21b --- /dev/null +++ b/src/Search/Filter/FilterOperator.php @@ -0,0 +1,48 @@ +'; + const LT = '<'; + const GTE = '>='; + const LTE = '<='; + const CONTAINS = 'CONTAINS'; + const NOT_CONTAINS = 'NOT_CONTAINS'; + + private string $operator; + + public function __construct(string $operator) + { + if (!in_array($operator, self::toArray(), true)) { + throw new \InvalidArgumentException(sprintf('invalid operator %s', $operator)); + } + + $this->operator = $operator; + } + + public function value(): string + { + return $this->operator; + } + + /** + * @return string[] + */ + public static function toArray(): array + { + return [ + self::EQ, + self::NE, + self::GT, + self::LT, + self::GTE, + self::LTE, + self::CONTAINS, + self::NOT_CONTAINS, + ]; + } +} diff --git a/src/Search/Filter/FilterValue.php b/src/Search/Filter/FilterValue.php new file mode 100644 index 0000000..f05edf9 --- /dev/null +++ b/src/Search/Filter/FilterValue.php @@ -0,0 +1,8 @@ +by = $by; + $this->type = $type; + $this->properties = $properties; + } + + public function orderBy(): Type + { + return $this->by; + } + + public function orderType(): OrderType + { + return $this->type; + } + + public function orderProperties(): array + { + return $this->properties; + } +} \ No newline at end of file diff --git a/src/Search/Order/OrderAscType.php b/src/Search/Order/OrderAscType.php new file mode 100644 index 0000000..c93a583 --- /dev/null +++ b/src/Search/Order/OrderAscType.php @@ -0,0 +1,8 @@ +limit = $limit; - $this->page = $page; + $this->offset = $offset; } } diff --git a/src/Search/Query.php b/src/Search/Query.php deleted file mode 100644 index da2a3aa..0000000 --- a/src/Search/Query.php +++ /dev/null @@ -1,14 +0,0 @@ -criteria = $criteria; + } +} diff --git a/src/Search/Query/SearchQueryHandler.php b/src/Search/Query/SearchQueryHandler.php new file mode 100644 index 0000000..6e339ca --- /dev/null +++ b/src/Search/Query/SearchQueryHandler.php @@ -0,0 +1,22 @@ +searchService = $searchService; + } + + public function handle(SearchQuery $q): SearchQueryResponse + { + $result = $this->searchService->search($q->criteria); + + return new SearchQueryResponse($result); + } +} diff --git a/src/Search/Query/SearchQueryResponse.php b/src/Search/Query/SearchQueryResponse.php new file mode 100644 index 0000000..75d4033 --- /dev/null +++ b/src/Search/Query/SearchQueryResponse.php @@ -0,0 +1,15 @@ +result = $result; + } +} diff --git a/src/Search/Result.php b/src/Search/Result.php index 0259cca..1aa8a41 100644 --- a/src/Search/Result.php +++ b/src/Search/Result.php @@ -2,19 +2,38 @@ namespace IQDEV\Search; -use IQDEV\Search\Document\DocumentCollection; +use IQDEV\Search\Document\ProductCollection; use IQDEV\Search\Facet\FacetCollection; class Result { - public DocumentCollection $hits; - public FacetCollection $facets; - public int $numPages = 0; - public int $numProduct = 0; + private ProductCollection $products; + private FacetCollection $facets; + private int $total = 0; public function __construct() { - $this->hits = new DocumentCollection(); + $this->products = new ProductCollection(); $this->facets = new FacetCollection(); } + + public function setTotal(int $total): void + { + $this->total = $total; + } + + public function getTotal(): int + { + return $this->total; + } + + public function getProducts(): ProductCollection + { + return $this->products; + } + + public function getFacets(): FacetCollection + { + return $this->facets; + } } diff --git a/src/Search/SearchQuery/SearchQuery.php b/src/Search/SearchQuery/SearchQuery.php deleted file mode 100644 index b41ae3e..0000000 --- a/src/Search/SearchQuery/SearchQuery.php +++ /dev/null @@ -1,114 +0,0 @@ - - *
  • - * filters - *
      - *
    • categoryId => 123
    • - *
    • ['min' => null, 'max' => 123]
    • - *
    • красный | [красный, желтый]
    • - *
    - *
  • - *
  • - * pagination - *
      - *
    • limit => 123
    • - *
    • page => 1
    • - *
    - *
  • - *
  • - * query => 'красный' - *
  • - *
  • - * order - *
      - *
    • by => 'smth.'
    • - *
    • direction => 'asc | desc'
    • - *
    - *
  • - * - * - * @return static - */ - public static function createFromArray(array $data): self - { - $instance = new self(); - - $filters = new FilterCollection(); - if (isset($data['filters'])) { - foreach ($data['filters'] as $code => $value) { - if ($code === 'categoryId') { - $filters->add(new FilterCategory($value)); - continue; - } - - if (is_array($value)) { - if (array_intersect(['min', 'max'], array_keys($value))) { - $value = array_map(static fn($v) => (float)$v, $value); - $filters->add(new FilterNumber($code, $value['min'] ?? 0, $value['max'] ?? PHP_INT_MAX)); - continue; - } - - $value = array_map(static fn($v) => (string)$v, $value); - } else { - $value = (string) $value; - } - - $filters->add(new FilterKeyword($code, $value)); - } - } - - if ($filters->isEmpty() === false) { - $instance->filters = $filters; - } - - if (isset($data['pagination']['limit'])) { - $instance->limit = (int) $data['pagination']['limit']; - } - - if (isset($data['pagination']['page'])) { - $instance->page = (int) $data['pagination']['page']; - } - - if (isset($data['query'])) { - $instance->query = $data['query']; - } - - if (isset($data['order'])) { - if (isset($data['order']['by'])) { - $instance->sortBy = $data['order']['by']; - } - - if (isset($data['order']['direction'])) { - $instance->sortDirection = $data['order']['direction']; - } - - if (isset($data['order']['type'])) { - // todo временное - $instance->sortType = $data['order']['type']; - } - } - - return $instance; - } -} diff --git a/src/Search/SearchQuery/SearchQueryHandler.php b/src/Search/SearchQuery/SearchQueryHandler.php deleted file mode 100644 index 5f459aa..0000000 --- a/src/Search/SearchQuery/SearchQueryHandler.php +++ /dev/null @@ -1,71 +0,0 @@ -searchService = $searchService; - } - - public function handle(SearchQuery $q): SearchResult - { - $query = new Query(); - - if ($q->filters) { - $query->filters = $q->filters; - } - - if ($q->query) { - $query->query = $q->query; - } - - if ($q->limit || $q->page) { - $query->pagination = new Pagination($q->limit, $q->page); - } - - if ($q->sortBy) { - $query->sorting = new SortingCollection(); - switch ($q->sortType) { - case 'field': - $query->sorting->add(new SortingFieldPair($q->sortBy, $q->sortDirection)); - break; - case 'property_keywords': - $query->sorting->add(new SortingPropertyKeywordPair($q->sortBy, $q->sortDirection)); - break; - case 'property_number': - $query->sorting->add(new SortingPropertyNumberPair($q->sortBy, $q->sortDirection)); - break; - default: - break; - } - } - - $result = $this->searchService->search($query); - - $searchResult = new SearchResult(); - foreach ($result->facets as $facet) { - $searchResult->facets->add($facet); - } - - foreach ($result->hits as $hit) { - $searchResult->hits->add($hit); - } - - $searchResult->numPages = $result->numPages; - $searchResult->numProduct = $result->numProduct; - - return $searchResult; - } -} \ No newline at end of file diff --git a/src/Search/SearchQuery/SearchResult.php b/src/Search/SearchQuery/SearchResult.php deleted file mode 100644 index b54ef42..0000000 --- a/src/Search/SearchQuery/SearchResult.php +++ /dev/null @@ -1,21 +0,0 @@ -hits = new DocumentCollection(); - $this->facets = new FacetCollection(); - } -} \ No newline at end of file diff --git a/src/Search/SearchService.php b/src/Search/SearchService.php index 33705a2..6a9ecea 100644 --- a/src/Search/SearchService.php +++ b/src/Search/SearchService.php @@ -4,5 +4,10 @@ namespace IQDEV\Search; interface SearchService { - public function search(Query $q): Result; -} \ No newline at end of file + /** + * @param Criteria $criteria + * + * @return Result + */ + public function search(Criteria $criteria): Result; +} diff --git a/src/Search/Sorting/Sorting.php b/src/Search/Sorting/Sorting.php deleted file mode 100644 index 673867c..0000000 --- a/src/Search/Sorting/Sorting.php +++ /dev/null @@ -1,8 +0,0 @@ -by = $by; - $this->direction = $direction; - } - - public function rule(): array - { - return [$this->by => $this->direction]; - } -} \ No newline at end of file diff --git a/src/Search/Sorting/SortingPropertyKeywordPair.php b/src/Search/Sorting/SortingPropertyKeywordPair.php deleted file mode 100644 index 6413b69..0000000 --- a/src/Search/Sorting/SortingPropertyKeywordPair.php +++ /dev/null @@ -1,8 +0,0 @@ -