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. |
리턴 | mixed |
/** * {@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]); }
/** * {@inheritdoc} */ public function apply(AbstractSearch $search, $bit) { $users = $this->users->getIdsForUsername($bit, $search->getActor()); $search->getQuery()->whereIn('id', $users); $search->setDefaultSort(['id' => $users]); }