Closed naumanahmed19 closed 7 years ago
okay I tried algolia and this worked for me but wondering why its not working with tntsearch
public function toSearchableArray()
{
$extra_data = [];
$extra_data['actors'] = array_map(function ($data) {
return $data['name'];
}
, $this->actors->toArray());
return array_merge($this->toArray(), $extra_data);
}
Someone did it?
//Edit
This is will not working in array_merge, because this function do array into array, scout need string, not array, i mean need string into array, not array :dancer:
"mb_strtolower() expects parameter 1 to be string, array given"
I trying to do something with this, but i don't have idea.
The problem is that the search driver cannot process array type model attributes, only strings.
Would this work? I'm attempting it now, but having other problems app/User.php:
public function toSearchableArray()
{
// there is definitely a cleaner way to do this
$search = collect($this->toArray())->only([
'name',
'email',
])->toArray();
// relevant section for relations
$search['address'] = isset($this->address)
? implode('', $this->address->toSearchableArray())
: '';
$search['profile'] = isset($this->profile)
? implode('', $this->profile->toSearchableArray())
: '';
return $search;
}
public function toSearchableArray()
{
$this->project;
$array = $this->toArray();
$array['project_name'] = $array['project']['title'];
unset($array['project']);
return $array;
}
I tryed this approach but if I search there is no project_name in my result.
Anyone solved this problem?
Did you reindex the data afterwards? If yes, how? What data do you have in your index after reindexing?
I ran php artisan scout:flush App\\Models\\MyModel
and then php artisan scout:import App\\Models\\MyModel
.
I tried php artisan tntsearch:import App\\Models\\MyModel
but this throws:
[PDOException]
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'project_name' i
n 'field list'
php artisan scout:import App\\Models\\MyModel
works but my result model has no project_name attribute.
Laravel: v5.3.28 laravel-scout-tntsearch-driver: v2.0.1
Your result model won't have an project_name
attribute since it doesn't exist on your model. It's still fetched as $model->project['title']
Thanks! Yes you are right =)
Hi, Thanks for this awesome package. Can you please tell me how to implement something like this I have 2 tables
Movies (hasManyActors) Actors (belongsToMovies)
now i want to search movies by actor name. I have read on forums that I may need to use egar load but how to implement this for larvel scout search?