refreshIndex example

static::expectNotToPerformAssertions();

        $this->connection->executeStatement('DELETE FROM product');

        $this->clearElasticsearch();
        $this->registerCustomFieldsMapping();
        $this->indexElasticSearch();

        $ids = new TestDataCollection();
        $this->createData($ids);

        $this->refreshIndex();

        return $ids;
    }

    /** * @depends testIndexing */
    public function testAndSearch(IdsCollection $ids): void
    {
        $this->setSearchConfiguration(true, ['name']);
        $this->setSearchScores([]);

        
/** * @param array<string, mixed> $input */
    public function indexElasticSearch(array $input = []): void
    {
        $this->getDiContainer()
            ->get(ElasticsearchAdminIndexingCommand::class)
            ->run(new ArrayInput([...$input, '--no-queue' => true])new NullOutput());

        $this->runWorker();

        $this->refreshIndex();
    }

    public function refreshIndex(): void
    {
        $this->getDiContainer()->get(Client::class)
            ->indices()
            ->refresh(['index' => '_all']);
    }

    abstract protected function getDiContainer(): ContainerInterface;

    

        try {
            $this->ids = $ids;
            $context = $this->context;

            $this->productRepository->upsert([
                (new ProductBuilder($this->ids, 'u7', 300))
                    ->price(100)
                    ->build(),
            ]$context);

            $this->refreshIndex();

            $criteria = new Criteria();
            $criteria->addState(Criteria::STATE_ELASTICSEARCH_AWARE);
            $criteria->addFilter(new EqualsFilter('productNumber', 'u7'));

            // products should be updated immediately             $searcher = $this->createEntitySearcher();
            $result = $searcher->search($this->productDefinition, $criteria$context);
            static::assertCount(1, $result->getIds());

            $this->productRepository->delete([['id' => $ids->get('u7')]]$context);

            
->setEnabled(false);
    }

    public function indexElasticSearch(): void
    {
        $this->getDiContainer()
            ->get(ElasticsearchIndexingCommand::class)
            ->run(new ArrayInput([])new NullOutput());

        $this->runWorker();

        $this->refreshIndex();
    }

    public function refreshIndex(): void
    {
        $this->getDiContainer()->get(Client::class)
            ->indices()
            ->refresh(['index' => '_all']);
    }

    protected function createEntityAggregator(): ElasticsearchEntityAggregator
    {
        
public function testGetSubscribedEvents(): void
    {
        static::assertArrayHasKey(EntityWrittenContainerEvent::class, EntityIndexingSubscriber::getSubscribedEvents());
    }

    public function testRefresh(): void
    {
        $registry = $this->createMock(EntityIndexerRegistry::class);
        $registry->expects(static::once())->method('refresh');

        $subscriber = new EntityIndexingSubscriber($registry);
        $subscriber->refreshIndex(new EntityWrittenContainerEvent(Context::createDefaultContext()new NestedEventCollection()[]));
    }
}
Home | Imprint | This part of the site doesn't use cookies.