mirror of
https://github.com/flarum/core.git
synced 2025-08-06 16:36:47 +02:00
fix: title scoring issues with group by clause
Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
@@ -30,7 +30,8 @@ class FulltextGambit implements GambitInterface
|
|||||||
$query = $search->getQuery();
|
$query = $search->getQuery();
|
||||||
$grammar = $query->getGrammar();
|
$grammar = $query->getGrammar();
|
||||||
|
|
||||||
$discussionSubquery = Discussion::select('id')
|
$discussionSubquery = Discussion::query()
|
||||||
|
->selectRaw('id as discussion_id')
|
||||||
->selectRaw('NULL as score')
|
->selectRaw('NULL as score')
|
||||||
->selectRaw('first_post_id as most_relevant_post_id')
|
->selectRaw('first_post_id as most_relevant_post_id')
|
||||||
->whereRaw('MATCH('.$grammar->wrap('discussions.title').') AGAINST (? IN BOOLEAN MODE)', [$bit]);
|
->whereRaw('MATCH('.$grammar->wrap('discussions.title').') AGAINST (? IN BOOLEAN MODE)', [$bit]);
|
||||||
@@ -52,17 +53,19 @@ class FulltextGambit implements GambitInterface
|
|||||||
// discussions that have a relevant title or that contain relevant posts.
|
// discussions that have a relevant title or that contain relevant posts.
|
||||||
$query
|
$query
|
||||||
->addSelect('posts_ft.most_relevant_post_id')
|
->addSelect('posts_ft.most_relevant_post_id')
|
||||||
|
->addSelect('posts_ft.score')
|
||||||
|
->selectRaw('MATCH('.$grammar->wrap('discussions.title').') AGAINST (?) as title_score', [$bit])
|
||||||
->join(
|
->join(
|
||||||
new Expression('('.$subquery->toSql().') '.$grammar->wrapTable('posts_ft')),
|
new Expression('('.$subquery->toSql().') '.$grammar->wrapTable('posts_ft')),
|
||||||
'posts_ft.discussion_id',
|
'posts_ft.discussion_id',
|
||||||
'=',
|
'=',
|
||||||
'discussions.id'
|
'discussions.id'
|
||||||
)
|
)
|
||||||
->groupBy('discussions.id')
|
->groupBy('posts_ft.discussion_id', 'title_score')
|
||||||
->addBinding($subquery->getBindings(), 'join');
|
->addBinding($subquery->getBindings(), 'join');
|
||||||
|
|
||||||
$search->setDefaultSort(function ($query) use ($grammar, $bit) {
|
$search->setDefaultSort(function ($query) {
|
||||||
$query->orderByRaw('MATCH('.$grammar->wrap('discussions.title').') AGAINST (?) desc', [$bit]);
|
$query->orderBy('title_score', 'desc');
|
||||||
$query->orderBy('posts_ft.score', 'desc');
|
$query->orderBy('posts_ft.score', 'desc');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user