shouldBeSearchable not working?
Jafo232 opened this issue · 5 comments
It seems that no matter what condition I set in shouldBeSearchable(), it doesn't matter. Example:
public function shouldBeSearchable()
{
return $this->approved === 1;
}
Even when approved is 0 for an item, it is still returned.
Yeah, can confirm it dosen't work. Kinda hard to implement too.
You can't create the fulltext index on only certain rows, all of it has go in there.
The problem is you can't really filter them away after getting them from the db either, that causes trouble if you want to filter och limit the results :/
Having the same issue...
I actually fixed the issue by setting the is_published
column in my database to boolean instead of a string.
For those who need a workaround you can override the search method and manually tack on where clauses to the Builder instance:
class MyModel extends Model
{
use Searchable {
search as traitSearch;
}
public static function search($query = '', $callback = null)
{
// Work around for https://github.com/yabhq/laravel-scout-mysql-driver/issues/84
return self::traitSearch($query, $callback)->where('attribute', 0);
}
}
Be aware of the limitations: https://laravel.com/docs/master/scout#where-clauses
@freshleafmedia the workaround works fine as long as you don't want to do do something like
whereNotNull
I got around it by doing this:
class MyModel extends Model
{
use Searchable {
search as traitSearch;
}
public static function search($query = '', $callback = null)
{
// Work around for https://github.com/yabhq/laravel-scout-mysql-driver/issues/84
return self::traitSearch($query, '\App\Models\MyModel::callBack');
}
public static function callBack($query, $engine)
{
return $query->whereNotNull('field_name');
}
}
another option is to simply add a callback when you do the ::search()
$result = MyModel::search('some text', '\App\Models\MyModel::callback')->get()