searchable
searchable copied to clipboard
Scope problem
Hi,
I am using searchable with own publishedScope (Global Scope) on laravel 5.2.5
PublishedScope
$builder->where('created_at', '<', Carbon::now());
When used like:
Watch::search($searchQuery)->get();
I get error.
When used like:
Watch::withoutGlobalScopes([PublishedScope::class])->search($searchQuery)->get();
No error it is works. But i must use that scope.
Model:
protected $searchable = [
'columns' => [
'watch_translations.title' => 10,
'watch_translations.excerpt' => 5,
'watch_translations.content' => 3,
],
'joins' => [
'watch_translations' => ['watches.id','watch_translations.watch_id'],
],
];
Error:
SQLSTATE[HY093]: Invalid parameter number (SQL: select * from (select `watches`.*, avg((case when LOWER(`watch_translations`.`title`) LIKE searchkeyword then 150 else 0 end) + (case when LOWER(`watch_translations`.`title`) LIKE searchkeyword% then 50 else 0 end) + (case when LOWER(`watch_translations`.`title`) LIKE %searchkeyword% then 10 else 0 end) + (case when LOWER(`watch_translations`.`excerpt`) LIKE searchkeyword then 75 else 0 end) + (case when LOWER(`watch_translations`.`excerpt`) LIKE searchkeyword% then 25 else 0 end) + (case when LOWER(`watch_translations`.`excerpt`) LIKE %searchkeyword% then 5 else 0 end) + (case when LOWER(`watch_translations`.`content`) LIKE searchkeyword then 45 else 0 end) + (case when LOWER(`watch_translations`.`content`) LIKE searchkeyword% then 15 else 0 end) + (case when LOWER(`watch_translations`.`content`) LIKE %searchkeyword% then 3 else 0 end)) as relevance from `watches` left join `watch_translations` on `watches`.`id` = `watch_translations`.`watch_id` where `watches`.`deleted_at` is null and `created_at` < 2015-12-31 11:54:59 group by `watches`.`id`, `watch_translations`.`title`, `watch_translations`.`excerpt`, `watch_translations`.`content` having relevance > 4.50 order by `relevance` desc, `position` asc) as `watches` where `watches`.`deleted_at` is null and `created_at` < ? order by `position` asc)```
I am experiencing this issue too. Did you find any solution to this?
Another bad solution I am trying now is to disable all global scopes, and apply them manually using regular scopes, but, it'd be nice to have global scopes running :joy:
I get same issue (with global scope).
Do you guys have solution to avoid this problem?
@tarik817 I ended up doing this (using repository pattern):
/**
* Search functionality.
*
* @param string $query
* @param int $limit
*
* @return Collection
*/
public function searchBy($query, $limit = 50)
{
return $this->model
->withoutGlobalScopes()
->applyScope1()
->applyScope2()
->search($query)
->limit($limit)
->get();
}
@mgarciadelojo Thank you for quick answer!
It's will help:)
I am experiencing the same issue with a global scope. This issue has been open since December 31st. Will this ever be fixed or is this package abandoned?
I'm acepting pull requests
Any update?