diff --git a/src/Builder.php b/src/Builder.php index cc600eb..187d635 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -145,7 +145,7 @@ protected function addSearchClauses( $this->searchWhere($subquery, $columns, $words, $whereBindings); } - $this->query->where('relevance', '>=', new Expression($threshold)); + $this->query->where('relevance', '>=', new Expression(number_format($threshold, 2))); $this->query->orders = array_merge( [['column' => 'relevance', 'direction' => 'desc']], diff --git a/tests/SearchableBuilderTest.php b/tests/SearchableBuilderTest.php index e55b6fe..c8a3c6d 100644 --- a/tests/SearchableBuilderTest.php +++ b/tests/SearchableBuilderTest.php @@ -35,7 +35,7 @@ public function single_character_wildcards() { $sql = 'select * from (select `users`.*, max(case when `users`.`last_name` = ? then 150 else 0 end) '. 'as relevance from `users` where (`users`.`last_name` like ?) '. - 'group by `users`.`primary_key`) as `users` where `relevance` >= 2.5 order by `relevance` desc'; + 'group by `users`.`primary_key`) as `users` where `relevance` >= 2.50 order by `relevance` desc'; $bindings = ['jaros_aw', 'jaros_aw']; @@ -157,7 +157,7 @@ public function additional_order_clauses() '+ case when `profiles`.`name` = ? then 15 else 0 end) as relevance '. 'from `users` left join `profiles` on `users`.`profile_id` = `profiles`.`id` '. 'where (`users`.`first_name` like ? or `profiles`.`name` like ?) group by `users`.`primary_key`) '. - 'as `users` where `relevance` >= 0.5 order by `relevance` desc, `first_name` asc'; + 'as `users` where `relevance` >= 0.50 order by `relevance` desc, `first_name` asc'; $bindings = ['jarek', 'jarek', 'jarek', 'jarek']; @@ -176,7 +176,7 @@ public function length_aware_pagination() '+ case when `users`.`last_name` like ? then 50 else 0 end '. '+ case when `users`.`last_name` like ? then 10 else 0 end) '. 'as relevance from `users` where (`users`.`last_name` like ?) '. - 'group by `users`.`primary_key`) as `users` where `relevance` >= 2.5'; + 'group by `users`.`primary_key`) as `users` where `relevance` >= 2.50'; $bindings = ['jarek', 'jarek%', '%jarek%', '%jarek%']; @@ -195,7 +195,7 @@ public function case_insensitive_operator_in_postgres() '+ case when "users"."last_name" ilike ? then 50 else 0 end '. '+ case when "users"."last_name" ilike ? then 10 else 0 end) '. 'as relevance from "users" where ("users"."last_name" ilike ?) '. - 'group by "users"."primary_key") as "users" where "relevance" >= 2.5 order by "relevance" desc'; + 'group by "users"."primary_key") as "users" where "relevance" >= 2.50 order by "relevance" desc'; $bindings = ['jarek', 'jarek%', '%jarek%', '%jarek%']; @@ -228,7 +228,7 @@ public function wildcard_search_by_default() '+ case when `users`.`last_name` like ? then 50 else 0 end '. '+ case when `users`.`last_name` like ? then 10 else 0 end) '. 'as relevance from `users` where (`users`.`last_name` like ?) '. - 'group by `users`.`primary_key`) as `users` where `relevance` >= 2.5 order by `relevance` desc'; + 'group by `users`.`primary_key`) as `users` where `relevance` >= 2.50 order by `relevance` desc'; $bindings = ['jarek', 'jarek%', '%jarek%', '%jarek%']; @@ -301,7 +301,7 @@ public function explicit_search_on_joined_table() 'as relevance from `users` left join `profiles` on `users`.`profile_id` = `profiles`.`id` '. 'where (`users`.`first_name` like ? or `users`.`first_name` like ? or `users`.`last_name` like ? or `users`.`last_name` like ? '. 'or `users`.`email` like ? or `users`.`email` like ? or `profiles`.`name` like ? or `profiles`.`name` like ?) '. - 'group by `users`.`primary_key`) as `users` where `relevance` >= 4.5 order by `relevance` desc'; + 'group by `users`.`primary_key`) as `users` where `relevance` >= 4.50 order by `relevance` desc'; $bindings = [ 'jarek', 'tkaczyk', 'jarek', 'tkaczyk', 'jarek', 'tkaczyk', 'jarek', 'tkaczyk',