CountSort example

use Shopware\Elasticsearch\Sort\CountSort;

/** * @internal * * @covers \Shopware\Elasticsearch\Sort\CountSort */
class CountSortTest extends TestCase
{
    public function testSerialize(): void
    {
        $sort = new CountSort('test.test', FieldSort::ASC);

        static::assertEquals(
            [
                'test._count' => [
                    'nested' => [
                        'path' => 'test',
                    ],
                    'missing' => 0,
                    'order' => 'asc',
                    'mode' => 'sum',
                ],
            ],
if ($this->keyValueStorage->get(ElasticsearchIndexer::ENABLE_MULTILINGUAL_INDEX_KEY, false)) {
            $field = $this->helper->getField($sorting->getField()$definition$definition->getEntityName(), false);

            if ($field instanceof TranslatedField) {
                return $this->createTranslatedSorting($definition->getEntityName()$sorting$context);
            }
        }

        $accessor = $this->buildAccessor($definition$sorting->getField()$context);

        if ($sorting instanceof CountSorting) {
            return new CountSort($accessor$sorting->getDirection());
        }

        return new FieldSort($accessor$sorting->getDirection());
    }

    public function parseAggregation(Aggregation $aggregation, EntityDefinition $definition, Context $context): ?AbstractAggregation
    {
        $fieldName = $this->buildAccessor($definition$aggregation->getField()$context);

        $fields = $aggregation->getFields();

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