Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FCBHDBP-616 improving response for search languages endpoint #3

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/Models/Language/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,12 @@ public function scopeFilterableByNameAndAccessGroup(
$formatted_name = "+$name*";

$lang = Language::from('languages', 'lang')
->select('lang.id as id')
->selectRaw('lang.id as id, (MATCH (lang.name) against (? IN BOOLEAN MODE) + IF(lang.name LIKE ?, 1000, 0)) as score', [$name, "$name%"])
->whereRaw('MATCH (lang.name) against (? IN BOOLEAN MODE)', [$formatted_name])
->isContentAvailable($access_group_ids, $bible_fileset_filters);

$lang_trans = LanguageTranslation::from('language_translations', 'lang_trans')
->select('lang_trans.language_source_id as id')
->selectRaw('lang_trans.language_source_id as id, (MATCH (lang_trans.name) against (? IN BOOLEAN MODE) + IF(lang_trans.name LIKE ?, 1000, 0)) as score', [$name, "$name%"])
->whereRaw('MATCH (lang_trans.name) against (? IN BOOLEAN MODE)', [$formatted_name])
->isContentAvailable($access_group_ids, $bible_fileset_filters)
->hasPriority();
Expand All @@ -498,7 +498,8 @@ public function scopeFilterableByNameAndAccessGroup(
->unionAll($lang_trans);

$lang_union_all_group = \DB::table($lang_union_query, 'lang_and_trans_group')
->groupBy('lang_and_trans_group.id');
->groupBy('lang_and_trans_group.id')
->orderBy('lang_and_trans_group.score', 'DESC');

return $query->joinSub(
$lang_union_all_group,
Expand Down