addSort example



    /** * {@inheritdoc} */
    public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addSort($this->getSorting($criteriaPart));
    }

    private function getSorting(PopularitySorting $criteriaPart): FieldSort
    {
        return new FieldSort('sales', strtolower($criteriaPart->getDirection())['unmapped_type' => 'long']);
    }
}
parent::__construct($entity_type$conjunction$namespaces);
    $this->connection = $connection;
  }

  /** * {@inheritdoc} */
  public function execute() {
    return $this
      ->prepare()
      ->compile()
      ->addSort()
      ->finish()
      ->result();
  }

  /** * Prepares the basic query with proper metadata/tags and base fields. * * @return $this * Returns the called object. * * @throws \Drupal\Core\Entity\Query\QueryException * Thrown if the base table does not exist. */


    /** * {@inheritdoc} */
    public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addSort($this->getSorting($criteriaPart));
    }

    private function getSorting(ProductStockSorting $criteriaPart): FieldSort
    {
        return new FieldSort('stock', strtolower($criteriaPart->getDirection())['unmapped_type' => 'keyword']);
    }
}


    /** * {@inheritdoc} */
    public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addSort($this->getSorting($criteriaPart));
    }

    private function getSorting(ProductNameSorting $criteriaPart): FieldSort
    {
        return new FieldSort('name.raw', strtolower($criteriaPart->getDirection())['unmapped_type' => 'long']);
    }
}

    public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $randomQuery = new FunctionScoreQuery(new MatchAllQuery());
        $randomQuery->addRandomFunction(md5(uniqid('swag', true)));

        $search->addSort(new FieldSort('_score'));
        $search->addQuery($randomQuery);
    }
}


    /** * {@inheritdoc} */
    public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addSort($this->getSorting($criteriaPart));
    }

    private function getSorting(ProductAttributeSorting $criteriaPart): FieldSort
    {
        $field = 'attributes.core.' . $criteriaPart->getField();

        return new FieldSort($fieldstrtolower($criteriaPart->getDirection()));
    }
}
public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $categoryCondition = $criteria->getBaseCondition('category');
        if (!$categoryCondition instanceof CategoryCondition) {
            return;
        }

        $search->addSort($this->getSorting($criteriaPart$categoryCondition));
    }

    private function getSorting(ManualSorting $criteriaPart, CategoryCondition $categoryCondition): FieldSort
    {
        $categoryId = $categoryCondition->getCategoryIds()[0];

        // Elasticsearch DSL does not support the new format         // @see: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-sort.html#_nested_sorting_examples         return new FieldSort('manualSorting.position', strtolower($criteriaPart->getDirection())[
            'unmapped_type' => 'integer',
            'nested' => [
                
/** * @return array */
    protected function getSearchFields()
    {
        return ['swag_all' => 1];
    }

    protected function addSortings(SearchCriteria $criteria, Search $search)
    {
        foreach ($criteria->sortings as $sorting) {
            $search->addSort(
                new FieldSort($sorting['property']strtolower($sorting['direction']))
            );
        }
    }

    private function addFilters(Search $search, SearchCriteria $criteria)
    {
        $query = new BoolQuery();
        foreach ($criteria->conditions as $condition) {
            if ($condition['property'] === 'search') {
                $search->addQuery(
                    
/** * {@inheritdoc} */
  public function execute() {
    return $this
      ->prepare()
      ->addAggregate()
      ->compile()
      ->compileAggregate()
      ->addGroupBy()
      ->addSort()
      ->addSortAggregate()
      ->finish()
      ->result();
  }

  /** * {@inheritdoc} */
  public function prepare() {
    parent::prepare();
    // Throw away the id fields.


    /** * {@inheritdoc} */
    public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addSort($this->getSorting($criteriaPart));
    }

    private function getSorting(SearchRankingSorting $criteriaPart): FieldSort
    {
        return new FieldSort('_score', strtolower($criteriaPart->getDirection()));
    }
}


    /** * {@inheritdoc} */
    public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addSort($this->getSorting($criteriaPart$criteria$context));
    }

    private function getSorting(PriceSorting $criteriaPart, Criteria $criteria, ShopContextInterface $context): FieldSort
    {
        $field = $this->mapper->getPriceField($criteria$context);

        return new FieldSort($fieldstrtolower($criteriaPart->getDirection())['unmapped_type' => 'double']);
    }
}
$ids = array_column($data, 'key');

        if (empty($ids)) {
            return;
        }

        $groupIds = $this->getGroupIds($ids);

        $search = new EsSearch();
        $search->addQuery(new IdsQuery($groupIds), BoolQuery::FILTER);
        $search->addQuery(new TermQuery('filterable', true), BoolQuery::FILTER);
        $search->addSort(new FieldSort('name', 'asc'));
        $search->setFrom(0);
        $search->setSize(self::AGGREGATION_SIZE);

        $index = $this->indexFactory->createShopIndex($context->getShop(), PropertyMapping::TYPE);

        $arguments = [
            'index' => $index->getName(),
            'body' => $search->toArray(),
            'rest_total_hits_as_int' => true,
            'track_total_hits' => true,
        ];

        
$this->addConditions($criteria$context$search);
        $this->addCriteriaParts($criteria$context$search$criteria->getSortings());
        $this->addCriteriaParts($criteria$context$search$criteria->getFacets());

        if ($criteria->getOffset() !== null) {
            $search->setFrom($criteria->getOffset());
        }
        if ($criteria->getLimit() !== null) {
            $search->setSize($criteria->getLimit());
        }

        $search->addSort(new FieldSort('id', 'asc'));

        return $search;
    }

    /** * @param CriteriaPartInterface[] $criteriaParts */
    private function addCriteriaParts(
        Criteria $criteria,
        ShopContextInterface $context,
        EsSearch $search,
        
$builder = $this->createProductImpressionBuilder($offset$limit);

        if ($from instanceof DateTimeInterface) {
            $builder->andWhere('articleImpression.date >= :fromDate')
                ->setParameter(':fromDate', $from->format('Y-m-d H:i:s'));
        }
        if ($to instanceof DateTimeInterface) {
            $builder->andWhere('articleImpression.date <= :toDate')
                ->setParameter(':toDate', $to->format('Y-m-d H:i:s'));
        }
        if ($sort !== []) {
            $this->addSort($builder$sort);
        }
        if (!empty($shopIds)) {
            foreach ($shopIds as $shopId) {
                $shopId = (int) $shopId;
                $builder->addSelect(
                    'SUM(IF(articleImpression.shopId = ' . $shopId . ', articleImpression.impressions, 0)) as totalImpressions' . $shopId
                );
            }
        }

        $builder = $this->eventManager->filter('Shopware_Analytics_ProductImpressions', $builder[
            


    /** * {@inheritdoc} */
    public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addSort($this->getSorting($criteriaPart));
    }

    private function getSorting(ReleaseDateSorting $criteriaPart): FieldSort
    {
        return new FieldSort('formattedCreatedAt', strtolower($criteriaPart->getDirection()),
            ['unmapped_type' => 'date']);
    }
}
Home | Imprint | This part of the site doesn't use cookies.