Ejemplo n.º 1
0
 /**
  * @param RequestQueryInterface $query
  * @return FilterInterface[]
  */
 private function getFilters($query)
 {
     $filters = [];
     switch ($query->getType()) {
         case RequestQueryInterface::TYPE_BOOL:
             /** @var \Magento\Framework\Search\Request\Query\BoolExpression $query */
             foreach ($query->getMust() as $subQuery) {
                 $filters = array_merge($filters, $this->getFilters($subQuery));
             }
             foreach ($query->getShould() as $subQuery) {
                 $filters = array_merge($filters, $this->getFilters($subQuery));
             }
             foreach ($query->getMustNot() as $subQuery) {
                 $filters = array_merge($filters, $this->getFilters($subQuery));
             }
             break;
         case RequestQueryInterface::TYPE_FILTER:
             /** @var Filter $query */
             $filter = $query->getReference();
             if (FilterInterface::TYPE_BOOL === $filter->getType()) {
                 $filters = array_merge($filters, $this->getFiltersFromBoolFilter($filter));
             } else {
                 $filters[] = $filter;
             }
             break;
         default:
             break;
     }
     return $filters;
 }
Ejemplo n.º 2
0
 /**
  * @param QueryInterface $query
  * @return bool
  */
 private function hasFilters(QueryInterface $query)
 {
     $hasFilters = false;
     switch ($query->getType()) {
         case RequestQueryInterface::TYPE_BOOL:
             /** @var \Magento\Framework\Search\Request\Query\Bool $query */
             foreach ($query->getMust() as $subQuery) {
                 $hasFilters |= $this->hasFilters($subQuery);
             }
             foreach ($query->getShould() as $subQuery) {
                 $hasFilters |= $this->hasFilters($subQuery);
             }
             foreach ($query->getMustNot() as $subQuery) {
                 $hasFilters |= $this->hasFilters($subQuery);
             }
             break;
         case RequestQueryInterface::TYPE_FILTER:
             $hasFilters |= true;
             break;
         default:
             $hasFilters |= false;
             break;
     }
     return $hasFilters;
 }