SuffixFilter example

new Criteria(),
            '749322be59780dc4034598e25b3cd946',
        ];

        yield 'prefix-filter' => [
            (new Criteria())->addFilter(new PrefixFilter('foo', 'bar')),
            'a3def85d7155b475e330761d1eb8b1f1',
        ];

        // this has a different hash because of a different filter type used         yield 'suffix-filter' => [
            (new Criteria())->addFilter(new SuffixFilter('foo', 'bar')),
            'fa6fcaab1e5a33f0c7fdedb61bef8d22',
        ];

        yield 'filter+sort' => [
            (new Criteria())->addFilter(new PrefixFilter('foo', 'bar'))->addSorting(new FieldSorting('foo')),
            'c5d7faee1a855cfdf7f4a5a8807ec0f0',
        ];

        yield 'filter+sort+sort-desc' => [
            (new Criteria())->addFilter(new PrefixFilter('foo', 'bar'))->addSorting(new FieldSorting('foo', FieldSorting::DESCENDING)),
            'fd5017a9b079d29a790ea9682c11ed74',
        ];
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\SuffixFilter;

/** * @internal * * @covers \Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\SuffixFilter */
class SuffixFilterTest extends TestCase
{
    public function testEncode(): void
    {
        $filter = new SuffixFilter('foo', 'bar');

        static::assertEquals(
            [
                'field' => 'foo',
                'value' => 'bar',
                'isPrimary' => false,
                'resolved' => null,
                'extensions' => [],
                '_class' => SuffixFilter::class,
            ],
            $filter->jsonSerialize()
        );
static::assertFalse($result->has($ids->get('product-2')));
    }

    /** * @depends testIndexing */
    public function testSuffixFilter(IdsCollection $ids): void
    {
        $criteria = new Criteria($ids->prefixed('product-'));
        // "ed" refers to the property "red" of "product-1" and "product-2"         $criteria->addFilter(
            new SuffixFilter('product.properties.name', 'ed')
        );
        // "low" refers to the property "yellow" of only "product-1"         $criteria->addFilter(
            new SuffixFilter('product.properties.name', 'low')
        );

        $result = $this->getContainer()->get('product.repository')
            ->searchIds($criteria, Context::createDefaultContext());

        static::assertEquals(1, $result->getTotal());
        static::assertTrue($result->has($ids->get('product-1')));
        
return new PrefixFilter(self::buildFieldName($definition$query['field'])$query['value']);
            case 'suffix':
                if (empty($query['field'])) {
                    throw DataAbstractionLayerException::invalidFilterQuery('Parameter "field" for suffix filter is missing.', $path . '/field');
                }

                if (!isset($query['value']) || $query['value'] === '') {
                    throw DataAbstractionLayerException::invalidFilterQuery('Parameter "value" for suffix filter is missing.', $path . '/value');
                }

                return new SuffixFilter(self::buildFieldName($definition$query['field'])$query['value']);

            case 'range':
                return new RangeFilter(self::buildFieldName($definition$query['field'])$query['parameters']);
            case 'until':
            case 'since':
                return self::getFilterByRelativeTime(self::buildFieldName($definition$query['field'])$query$path);
            case 'equalsAll':
                if (empty($query['field'])) {
                    throw DataAbstractionLayerException::invalidFilterQuery('Parameter "field" for equalsAny filter is missing.', $path . '/field');
                }

                
$criteria = (new Criteria())->addFilter(new PrefixFilter('link', '\\ '));
        $foundIds = $this->manufacturerRepository->searchIds($criteria, Context::createDefaultContext());

        static::assertContains($targetId$foundIds->getIds());
        static::assertNotContains($erroneousId$foundIds->getIds());
    }

    public function testSuffixFilterFindUnderscore(): void
    {
        $targetId = $this->createManufacturer(['link' => 'target_to_find']);
        $erroneousId = $this->createManufacturer(['link' => 'target to find']);
        $criteria = (new Criteria())->addFilter(new SuffixFilter('link', 'to_find'));
        $foundIds = $this->manufacturerRepository->searchIds($criteria, Context::createDefaultContext());

        static::assertContains($targetId$foundIds->getIds());
        static::assertNotContains($erroneousId$foundIds->getIds());
    }

    public function testSuffixFilterFindPercentageSign(): void
    {
        $targetId = $this->createManufacturer(['link' => 'target%find']);
        $erroneousId = $this->createManufacturer(['link' => 'target to find']);
        $criteria = (new Criteria())->addFilter(new SuffixFilter('link', 'et%find'));
        


    /** * @depends testIndexing */
    public function testSuffixFilter(IdsCollection $data): void
    {
        try {
            $searcher = $this->createEntitySearcher();
            $criteria = new Criteria();
            $criteria->addState(Criteria::STATE_ELASTICSEARCH_AWARE);
            $criteria->addFilter(new SuffixFilter('product.name', 'tilk'));

            $products = $searcher->search($this->productDefinition, $criteria$this->context);
            static::assertCount(1, $products->getIds());
            static::assertSame(1, $products->getTotal());
            static::assertContains($data->get('product-3')$products->getIds());

            $criteria = new Criteria();
            $criteria->addState(Criteria::STATE_ELASTICSEARCH_AWARE);
            $criteria->addFilter(new SuffixFilter('product.name', 'subber'));

            $products = $searcher->search($this->productDefinition, $criteria$this->context);
            
'query' => 'foo',
                    'fields' => [
                        'name.' . self::SECOND_LANGUAGE . '.search',
                        'name.' . Defaults::LANGUAGE_SYSTEM . '.search',
                    ],
                    'type' => 'phrase_prefix',
                    'slop' => 5,
                ],
            ],
        ];
        yield 'SuffixFilter field' => [
            new SuffixFilter('productNumber', 'foo'),
            [
                'wildcard' => [
                    'productNumber' => [
                        'value' => '*foo',
                    ],
                ],
            ],
        ];
        yield 'SuffixFilter translated field' => [
            new SuffixFilter('name', 'foo'),
            [
                
Home | Imprint | This part of the site doesn't use cookies.