Skip to content

Commit

Permalink
Prioritize exact matches in manager search results (#16388)
Browse files Browse the repository at this point in the history
  • Loading branch information
halftrainedharry committed Mar 27, 2023
1 parent 31ad611 commit a3937a8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/src/Revolution/Processors/Search/Search.php
Expand Up @@ -131,6 +131,7 @@ protected function searchResources()
];
$c->where($querySearch, $queryContext);

$c->sortby('IF(`modResource`.`pagetitle` = ' . $this->modx->quote($this->query) . ', 0, 1)');
$c->sortby('modResource.createdon', 'DESC');

$c->limit($this->getMaxResults());
Expand Down Expand Up @@ -172,6 +173,8 @@ protected function searchElements($class, $type = '', $nameField = 'name', $desc
$querySearch['OR:id:='] = $this->query;
$c->where($querySearch);

$c->sortby('IF(`' . $nameField . '` = ' . $this->modx->quote($this->query) . ', 0, 1)');

$c->limit($this->getMaxResults());

$collection = $this->modx->getIterator($class, $c);
Expand Down Expand Up @@ -205,6 +208,8 @@ protected function searchUsers()
'OR:id:=' => $this->query,
]);

$c->sortby('IF(`username` = ' . $this->modx->quote($this->query) . ', 0, 1)');

$c->limit($this->getMaxResults());

/** @var modUserProfile[] $collection */
Expand Down

0 comments on commit a3937a8

Please sign in to comment.