Beispiel #1
0
 /**
  * Modifies the given query and adds the parameters necessary
  * for result grouping.
  *
  * @param Query $query The query to modify
  * @return Query The modified query with grouping parameters
  */
 public function modifyQuery(Query $query)
 {
     $query->setGrouping();
     $query->setNumberOfResultsPerGroup($this->findHighestGroupResultsLimit());
     if (!empty($this->groupingConfiguration['numberOfGroups'])) {
         $query->setNumberOfGroups($this->groupingConfiguration['numberOfGroups']);
     }
     $configuredGroups = $this->groupingConfiguration['groups.'];
     foreach ($configuredGroups as $groupName => $groupConfiguration) {
         if (isset($groupConfiguration['field'])) {
             $query->addGroupField($groupConfiguration['field']);
         } elseif (isset($groupConfiguration['query'])) {
             $query->addGroupQuery($groupConfiguration['query']);
         }
         if (isset($groupConfiguration['sortBy'])) {
             $query->addGroupSorting($groupConfiguration['sortBy']);
         }
     }
     return $query;
 }