hasQueriesOrTerm example



    /** * @param array<FieldSorting> $sortings */
    public function addSortings(EntityDefinition $definition, Criteria $criteria, array $sortings, QueryBuilder $query, Context $context): void
    {
        foreach ($sortings as $sorting) {
            $this->validateSortingDirection($sorting->getDirection());

            if ($sorting->getField() === '_score') {
                if (!$this->hasQueriesOrTerm($criteria)) {
                    continue;
                }

                // Only add manual _score sorting if the query contains a _score calculation and selection (i.e. the                 // criteria has a term or queries). Otherwise the SQL selection would fail because no _score field                 // exists in any entity.                 $query->addOrderBy('_score', $sorting->getDirection());
                $query->addState('_score');

                continue;
            }

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