Skip to content

Commit

Permalink
Move the index scope to a new namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Jul 3, 2024
1 parent e0d2642 commit ec56b35
Show file tree
Hide file tree
Showing 33 changed files with 76 additions and 77 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"doctrine/persistence": "^2.5 || ^3.0",
"liip/imagine-bundle": "^2.10",
"meilisearch/meilisearch-php": "^1.8",
"ocramius/doctrine-batch-utils": "^2.6",
"psr/cache": "^1.0 || ^2.0 || ^3.0",
"psr/event-dispatcher": "^1.0",
"psr/log": "^1.1 || ^2.0 || ^3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/DataMapper/CompositeDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Setono\CompositeCompilerPass\CompositeService;
use Setono\SyliusMeilisearchPlugin\Document\Document;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;

/**
* @extends CompositeService<DataMapperInterface>
Expand Down
2 changes: 1 addition & 1 deletion src/DataMapper/DataMapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Setono\SyliusMeilisearchPlugin\DataMapper;

use Setono\SyliusMeilisearchPlugin\Document\Document;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;

interface DataMapperInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/DataMapper/ImageUrlsDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Setono\SyliusMeilisearchPlugin\Document\Document;
use Setono\SyliusMeilisearchPlugin\Document\ImageUrlsAwareInterface;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;
use Sylius\Component\Core\Model\ImagesAwareInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Webmozart\Assert\Assert;
Expand Down
2 changes: 1 addition & 1 deletion src/DataMapper/IndexableDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Setono\SyliusMeilisearchPlugin\DataMapper;

use Setono\SyliusMeilisearchPlugin\Document\Document;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;

final class IndexableDataMapper implements DataMapperInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/DataMapper/Product/PriceDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Setono\SyliusMeilisearchPlugin\Document\Document;
use Setono\SyliusMeilisearchPlugin\Document\Product as ProductDocument;
use function Setono\SyliusMeilisearchPlugin\formatAmount;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;
use Sylius\Component\Channel\Model\ChannelInterface as BaseChannelInterface;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/DataMapper/Product/ProductDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Setono\SyliusMeilisearchPlugin\DataMapper\DataMapperInterface;
use Setono\SyliusMeilisearchPlugin\Document\Document;
use Setono\SyliusMeilisearchPlugin\Document\Product;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;
use Sylius\Component\Core\Model\ProductInterface;
use Webmozart\Assert\Assert;

Expand Down
2 changes: 1 addition & 1 deletion src/DataMapper/Product/TaxonCodesDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Setono\SyliusMeilisearchPlugin\DataMapper\DataMapperInterface;
use Setono\SyliusMeilisearchPlugin\Document\Document;
use Setono\SyliusMeilisearchPlugin\Document\Product as ProductDocument;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Taxonomy\Model\TaxonInterface;
use Webmozart\Assert\Assert;
Expand Down
2 changes: 1 addition & 1 deletion src/DataMapper/Taxon/TaxonDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Setono\SyliusMeilisearchPlugin\DataMapper\DataMapperInterface;
use Setono\SyliusMeilisearchPlugin\Document\Document;
use Setono\SyliusMeilisearchPlugin\Document\Taxon;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;
use Sylius\Component\Core\Model\TaxonInterface;
use Webmozart\Assert\Assert;

Expand Down
2 changes: 1 addition & 1 deletion src/DataMapper/UrlDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Setono\SyliusMeilisearchPlugin\Document\Document;
use Setono\SyliusMeilisearchPlugin\Document\UrlAwareInterface;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\UrlGenerator\EntityUrlGeneratorInterface;
use Webmozart\Assert\Assert;

Expand Down
2 changes: 1 addition & 1 deletion src/Document/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Setono\SyliusMeilisearchPlugin\Document;

use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Settings\IndexSettings;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Document/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Setono\SyliusMeilisearchPlugin\Document;

use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Settings\IndexSettings;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Document/Taxon.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Setono\SyliusMeilisearchPlugin\Document;

use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Settings\IndexSettings;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Filter/Object/CompositeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Setono\SyliusMeilisearchPlugin\Filter\Object;

use Setono\SyliusMeilisearchPlugin\Document\Document;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;

final class CompositeFilter implements FilterInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Filter/Object/FilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Setono\SyliusMeilisearchPlugin\Filter\Object;

use Setono\SyliusMeilisearchPlugin\Document\Document;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;

interface FilterInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Filter/Object/FilterableFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Setono\SyliusMeilisearchPlugin\Filter\Object;

use Setono\SyliusMeilisearchPlugin\Document\Document;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Model\FilterableInterface;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;

final class FilterableFilter implements FilterInterface
{
Expand Down
41 changes: 0 additions & 41 deletions src/IndexScope/IndexScope.php

This file was deleted.

25 changes: 20 additions & 5 deletions src/Indexer/DefaultIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Setono\SyliusMeilisearchPlugin\Indexer;

use Doctrine\Persistence\ManagerRegistry;
use DoctrineBatchUtils\BatchProcessing\SelectBatchIteratorAggregate;
use Meilisearch\Client;
use Setono\Doctrine\ORMTrait;
use Setono\SyliusMeilisearchPlugin\Config\Index;
Expand Down Expand Up @@ -51,16 +52,18 @@ public function indexEntities(array $entities): void
}

foreach ($this->indexScopeProvider->getAll($this->index) as $indexScope) {
$documents = [];

foreach ($entities as $entity) {
$document = new $this->index->document();
$this->dataMapper->map($entity, $document, $indexScope);

$this->objectFilter->filter($entity, $document, $indexScope);

$data = $this->normalize($document);

$this->client->index($this->indexNameResolver->resolveFromIndexScope($indexScope))->addDocuments([$data]);
$documents[] = $this->normalize($document);
}

$this->client->index($this->indexNameResolver->resolveFromIndexScope($indexScope))->addDocuments($documents, 'id');
}
}

Expand All @@ -82,8 +85,20 @@ public function removeEntities(array $entities): void
*/
protected function indexEntityClass(string $entity): void
{
// todo use Ocramius' batch library
throw new \RuntimeException('Not implemented');
$q = $this
->getManager($entity)
->createQueryBuilder()
->select('o')
->from($entity, 'o')
->getQuery()
;

/** @var SelectBatchIteratorAggregate<array-key, IndexableInterface> $objects */
$objects = SelectBatchIteratorAggregate::fromQuery($q, 100);

foreach ($objects as $object) {
$this->indexEntity($object);
}
}

// todo move this to a service
Expand Down
2 changes: 1 addition & 1 deletion src/Model/FilterableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Setono\SyliusMeilisearchPlugin\Model;

use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;

/**
* Implement this interface on entities that you want to filter in a simple way
Expand Down
1 change: 0 additions & 1 deletion src/Provider/IndexScope/CompositeIndexScopeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Setono\SyliusMeilisearchPlugin\Provider\IndexScope;

use Setono\SyliusMeilisearchPlugin\Config\Index;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;

final class CompositeIndexScopeProvider implements IndexScopeProviderInterface
{
Expand Down
1 change: 0 additions & 1 deletion src/Provider/IndexScope/DefaultIndexScopeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Setono\SyliusMeilisearchPlugin\Provider\IndexScope;

use Setono\SyliusMeilisearchPlugin\Config\Index;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;

final class DefaultIndexScopeProvider implements IndexScopeProviderInterface
{
Expand Down
21 changes: 21 additions & 0 deletions src/Provider/IndexScope/IndexScope.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusMeilisearchPlugin\Provider\IndexScope;

use Setono\SyliusMeilisearchPlugin\Config\Index;

final class IndexScope
{
public function __construct(
/**
* The index that this scope applies to
*/
public readonly Index $index,
public readonly ?string $channelCode = null,
public readonly ?string $localeCode = null,
public readonly ?string $currencyCode = null,
) {
}
}
1 change: 0 additions & 1 deletion src/Provider/IndexScope/IndexScopeProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Setono\SyliusMeilisearchPlugin\Provider\IndexScope;

use Setono\SyliusMeilisearchPlugin\Config\Index;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;

/**
* The responsibility of the index scope provider is to provide all the relevant index scopes for a given index
Expand Down
1 change: 0 additions & 1 deletion src/Provider/IndexScope/ProductIndexScopeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Setono\SyliusMeilisearchPlugin\Provider\IndexScope;

use Setono\SyliusMeilisearchPlugin\Config\Index;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
Expand Down
1 change: 0 additions & 1 deletion src/Provider/IndexScope/TaxonIndexScopeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Setono\SyliusMeilisearchPlugin\Provider\IndexScope;

use Setono\SyliusMeilisearchPlugin\Config\Index;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Locale\Context\LocaleContextInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/IndexSettings/IndexSettingsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Setono\SyliusMeilisearchPlugin\Provider\IndexSettings;

use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Settings\IndexSettings;

final class IndexSettingsProvider implements IndexSettingsProviderInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Setono\SyliusMeilisearchPlugin\Provider\IndexSettings;

use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Settings\IndexSettings;

interface IndexSettingsProviderInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Resolver/IndexName/IndexNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Setono\SyliusMeilisearchPlugin\Config\Index;
use Setono\SyliusMeilisearchPlugin\Config\IndexRegistryInterface;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScopeProviderInterface;
use Sylius\Component\Resource\Model\ResourceInterface;

Expand Down
2 changes: 1 addition & 1 deletion src/Resolver/IndexName/IndexNameResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Setono\SyliusMeilisearchPlugin\Resolver\IndexName;

use Setono\SyliusMeilisearchPlugin\Config\Index;
use Setono\SyliusMeilisearchPlugin\IndexScope\IndexScope;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;
use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\IndexScope;

interface IndexNameResolverInterface
{
Expand Down
5 changes: 5 additions & 0 deletions tests/Application/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

/node_modules

###> meilisearch ###
/data.ms/
/meilisearch
###< meilisearch ###

###> symfony/framework-bundle ###
/.env.*.local
/.env.local
Expand Down
7 changes: 7 additions & 0 deletions tests/Application/meilisearch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

if [ ! -f meilisearch ]; then
curl -L https://install.meilisearch.com | sh
fi

./meilisearch --master-key="aSampleMasterKey"
Empty file.
Loading

0 comments on commit ec56b35

Please sign in to comment.