setDefaultSort() public method

Set the default sort order for the search. This will only be applied if a sort order has not been specified in the search criteria.
public setDefaultSort ( array $defaultSort ) : mixed
$defaultSort array An array of sort-order pairs, where the column is the key, and the order is the value. The order may be 'asc', 'desc', or an array of IDs to order by.
return mixed
Example #1
0
 /**
  * {@inheritdoc}
  */
 public function apply(AbstractSearch $search, $bit)
 {
     if (!$search instanceof DiscussionSearch) {
         throw new LogicException('This gambit can only be applied on a DiscussionSearch');
     }
     $relevantPostIds = $this->fulltext->match($bit);
     $discussionIds = array_keys($relevantPostIds);
     $search->setRelevantPostIds($relevantPostIds);
     $search->getQuery()->whereIn('id', $discussionIds);
     $search->setDefaultSort(['id' => $discussionIds]);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function apply(AbstractSearch $search, $bit)
 {
     $users = $this->users->getIdsForUsername($bit, $search->getActor());
     $search->getQuery()->whereIn('id', $users);
     $search->setDefaultSort(['id' => $users]);
 }