getLastId example


        $timestamp = (new \DateTime())->getTimestamp();
        $offset = new IndexerOffset(
            ['foo', 'bar'],
            ['product', 'product_manufacturer'],
            $timestamp
        );

        static::assertEquals(ProductDefinition::ENTITY_NAME, $offset->getDefinition());
        static::assertTrue($offset->hasNextDefinition());
        static::assertSame($timestamp$offset->getTimestamp());
        static::assertNull($offset->getLastId());

        $offset->selectNextDefinition();

        static::assertEquals(ProductManufacturerDefinition::ENTITY_NAME, $offset->getDefinition());
        static::assertEmpty($offset->getDefinitions());
        static::assertFalse($offset->hasNextDefinition());

        $offset->resetDefinitions();

        static::assertEquals(ProductDefinition::ENTITY_NAME, $offset->getDefinition());
        static::assertEquals(
            [
private function createIndexingMessage(IndexerOffset $offset, Context $context): ?ElasticsearchIndexingMessage
    {
        $definition = $this->registry->get((string) $offset->getDefinition());

        if (!$definition) {
            throw new \RuntimeException(sprintf('Definition %s not found', $offset->getDefinition()));
        }

        $entity = $definition->getEntityDefinition()->getEntityName();

        $iterator = $this->iteratorFactory->createIterator($definition->getEntityDefinition()$offset->getLastId()$this->indexingBatchSize);

        $ids = $iterator->fetch();

        // current definition in current language has more ids to index         if (!empty($ids)) {
            // increment last id with iterator offset             $offset->setLastId($iterator->getOffset());

            $alias = $this->helper->getIndexName($definition->getEntityDefinition()(string) $offset->getLanguageId());

            $index = $alias . '_' . $offset->getTimestamp();

            
public function generateCondition(
        ConditionInterface $condition,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        $this->addCondition($condition$query);
    }

    private function addCondition(LastProductIdCondition $condition, QueryBuilder $query): void
    {
        $query->andWhere('product.id > :lastId')
            ->setParameter('lastId', $condition->getLastId());
    }
}
private function createIndexingMessage(IndexerOffset $offset): ?ElasticsearchIndexingMessage
    {
        $definition = $this->registry->get((string) $offset->getDefinition());

        if (!$definition) {
            throw ElasticsearchIndexingException::definitionNotFound((string) $offset->getDefinition());
        }

        $entity = $definition->getEntityDefinition()->getEntityName();

        $iterator = $this->iteratorFactory->createIterator($definition->getEntityDefinition()$offset->getLastId()$this->indexingBatchSize);

        $ids = $iterator->fetch();

        if (empty($ids)) {
            if (!$offset->hasNextDefinition()) {
                return null;
            }
            // increment definition offset             $offset->selectNextDefinition();

            // reset last id to start iterator at the beginning
CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(LastProductIdCondition $criteriaPart): RangeQuery
    {
        return new RangeQuery('id', [
            'gt' => $criteriaPart->getLastId(),
        ]);
    }
}
Home | Imprint | This part of the site doesn't use cookies.