Skip to content
Snippets Groups Projects
BaseIndexProvider.php 2.04 KiB
Newer Older
<?php

namespace IQDEV\ElasticSearch\Indexer;

use IQDEV\ElasticSearch\Configuration;
use IQDEV\ElasticSearch\Document\ProductDocument;
use IQDEV\ElasticSearch\Document\Property\Property;
use IQDEV\ElasticSearch\Document\Property\PropertyType;
use IQDEV\ElasticSearch\Facet\FacetFactory;
Pavel's avatar
Pavel committed
    private ?int $size = null;
    private ?int $limit = null;
    public function __construct(
        private array $products,
        private Configuration $configuration
    ) {
    }

    public function get(): \Generator
    {
        foreach ($this->products as $product) {
            $document = new ProductDocument(
                FacetFactory::createFromProperty(new Property('category_id', PropertyType::BASE), $product['category'])
            );

Pavel's avatar
Pavel committed
            $document->setAdditionData($product['data'] ?? []);
                foreach ($values as $key => $value) {
                        $document->getNumberFacets()->add(
                            FacetFactory::createFromProperty(new Property($key, PropertyType::NUMBER), $value)
                        );
                        $document->getKeywordFacets()->add(
                            FacetFactory::createFromProperty(new Property($key, PropertyType::KEYWORD), $value)
                        );
Pavel's avatar
Pavel committed
            $document->setSearchContent($product['name']);
Pavel's avatar
Pavel committed
            yield new AddIndex(
Pavel's avatar
Pavel committed

    public function setBatchSize(int $size): void
    {
        $this->size = $size;
    }

    public function getBatchSize(): ?int
    {
        return $this->size;
    }

    public function setLimit(int $limit): void
    {
        $this->limit = $limit;
    }

    public function getLimit(): ?int
    {
        return $this->limit;
    }
}