getKeyword example

$analyzed = $this->analyzer->analyze($product$context$configFields);

            $productId = Uuid::fromHexToBytes($product->getId());

            foreach ($analyzed as $keyword) {
                $keywords[] = [
                    'id' => Uuid::randomBytes(),
                    'version_id' => $versionId,
                    'product_version_id' => $versionId,
                    'language_id' => $languageId,
                    'product_id' => $productId,
                    'keyword' => $keyword->getKeyword(),
                    'ranking' => $keyword->getRanking(),
                    'created_at' => $now,
                ];
                $key = $keyword->getKeyword() . $languageId;
                $dictionary[$key] = [
                    'id' => Uuid::randomBytes(),
                    'language_id' => $languageId,
                    'keyword' => $keyword->getKeyword(),
                ];
            }
        }

        
$criteria->addAssociation('searchKeywords');

        /** @var ProductEntity|null $product */
        $product = $this->repository
            ->search($criteria$this->context)
            ->get($id);

        static::assertInstanceOf(ProductEntity::class$product);

        static::assertInstanceOf(ProductSearchKeywordCollection::class$product->getSearchKeywords());

        $keywords = $product->getSearchKeywords()->map(static fn (ProductSearchKeywordEntity $entity) => $entity->getKeyword());

        static::assertContains('default', $keywords);
        static::assertContains('name', $keywords);

        $update = [
            'id' => $id,
            'name' => 'updated',
        ];

        $this->repository->update([$update]$this->context);

        
'nestedField' => [
                'value' => 'nested',
                'second' => 'ignored',
            ],
            'ignored' => 'ignored',
        ]);

        $analyzer = $this->getContainer()->get(ProductSearchKeywordAnalyzer::class);

        $result = $analyzer->analyze($product, Context::createDefaultContext()$config);

        $words = $result->map(fn (AnalyzedKeyword $keyword) => $keyword->getKeyword());

        static::assertEquals(
            ['searchable', 'match', 'array', '10000000', '10.99999', 'nested'],
            array_values($words)
        );
    }

    /** * @dataProvider casesSearchBaseOnConfigField */
    public function testInsertIntoSearchKeywordForEn(bool $searchable, bool $tokenize, int $ranking): void
    {

#[Package('inventory')] class AnalyzedKeywordCollection extends Collection
{
    /** * @param AnalyzedKeyword $element */
    public function add($element): void
    {
        $this->validateType($element);

        $keyword = $element->getKeyword();
        $this->elements[$keyword] = $this->getBest($element$keyword);
    }

    /** * @param string|int $key * @param AnalyzedKeyword $element */
    public function set($key$element): void
    {
        $this->validateType($element);

        
Home | Imprint | This part of the site doesn't use cookies.