You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
8.79 added fulltext support for MySQL and Postgres via the whereFullText() and orWhereFullText() methods. However when doing a natural language search you often want to sort the returned results by rank, but currently there appears no way to do this, leaving us to build the query manually depending on the underlying DB.
Ideally an inFullTextOrder($alias) method would abstract this away (named to keep convention with the existing inRandomOrder() method). I have essentially implemented this for MySQL:
public function inFullTextOrder($as = 'rank', $direction = 'desc')
{
$where = Arr::first($this->wheres, fn($where) => $where['type'] == 'Fulltext');
$query = $this->grammar->whereFullText($this, $where);
if ($this->columns === null) {
$this->select('*');
}
$this->selectRaw(
'('.$query.') as '.$this->grammar->wrap($as), [$where['value']]
);
$this->orderBy($as, $direction);
}
however Postgres (which I'm not familiar with) obviously requires a different syntax. Happy to attempt and do a PR if useful / the right way to go.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
8.79 added fulltext support for MySQL and Postgres via the
whereFullText()
andorWhereFullText()
methods. However when doing a natural language search you often want to sort the returned results by rank, but currently there appears no way to do this, leaving us to build the query manually depending on the underlying DB.Ideally an
inFullTextOrder($alias)
method would abstract this away (named to keep convention with the existinginRandomOrder()
method). I have essentially implemented this for MySQL:however Postgres (which I'm not familiar with) obviously requires a different syntax. Happy to attempt and do a PR if useful / the right way to go.
Beta Was this translation helpful? Give feedback.
All reactions