Closed cawrvus closed 7 years ago
May be a silly question but did you index your model? :) On Sun, 28 May 2017 at 12:39, maranovot notifications@github.com wrote:
Hey, I have set up Laravel Scout with tntsearch according to the documentation. Only thing I did on top was that I set up database queue driver. When I try to search a model with the ::search all I get is empty array.
Controller test function:
public function test() { $search = Store::search('test')->get(); return view('test')->with('search', $search); }
Store model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Laravel\Scout\Searchable;
class Store extends Model { use SoftDeletes;
use Searchable; protected $dates = ['deleted_at']; protected $fillable = ['name', 'url', 'contact', 'description', 'detail', 'featured', 'network_id', 'currency_id', 'link', 'comment', 'category_id']; protected $with = ['favoritable']; /** * Get the indexable data array for the model. * * @return array */ public function toSearchableArray() { $array = $this->toArray(); // Customize array... return $array; } public function categories() { return $this->belongsToMany('App\Category'); } public function network() { return $this->belongsTo('App\Network'); } public function currency() { return $this->belongsTo('App\Currency'); } public function favoritable() { return $this->belongsTo('App\Favoritable', 'favoritable_id', 'favoritable_id'); }
}
the result is :
[ ]
Do you know what can cause this.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/teamtnt/laravel-scout-tntsearch-driver/issues/94, or mute the thread https://github.com/notifications/unsubscribe-auth/ACDDWtFSFJnJagU5s-bpG05sq-UjRlTYks5r-U7kgaJpZM4NonIP .
Yes I did it with the scout:import command and I can see the stores.index in my storage folder
He, put something in your array just to try, something like:
public function toSearchableArray()
{
$array = Array();
$array['name'] = $this->name;
$array['description'] = $this->description;
$array['url'] = $this->url;
return $array;
}
And now look for something that you are totally sure that is indexed, like some name. Let´s see what the search returns now.
@joelarmad I did what you suggested but still the result is empty array. My stores table contains only one store with the name 'test' so there is no way to miss on my end. Maybe the stores aren't indexed? How should the stores.index file look like?
Index is just a sqlite database so open it up in your sql viewer tool and check if there is really there :)
On Mon, May 29, 2017 at 11:15 AM maranovot notifications@github.com wrote:
@joelarmad https://github.com/joelarmad I did what you suggested but still the result is empty array. My stores table contains only one store with the name 'test' so there is no way to miss on my end. Maybe the stores aren't indexed? How should the stores.index file look like?
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/teamtnt/laravel-scout-tntsearch-driver/issues/94#issuecomment-304614078, or mute the thread https://github.com/notifications/unsubscribe-auth/ACDDWuuvofKpcH5ZQ9swcpPMFYFXclMxks5r-oyigaJpZM4NonIP .
Let´s put some foo data:
public function toSearchableArray()
{
$array = Array();
$array['name'] = 'Maranotov';
$array['description'] = 'My foo data';
$array['url'] = 'www.mysite.com';
return $array;
}
If is not installed install tinker and using it search in your index and let's see what happens: php artisan tinker App\Store::search('Maranotov')->get();
Ok, so I don't know why but indexing with scout:import command doesn't work but the tntsearch:import does work. So when using tntsearch:import command everything works perfectly.
EDIT : everything works except I must hardcode the toSearchableArray method doing only return this->toArray doesn't work.
@maranovot you mentioned that you queued the indexing, which means you need to run php artisan queue:work
to actually do the indexing process
Ok, so I did php artisan tntsearch:import App\\Store
then I did the php artisan queue:work
. And it seems to be working now, the return $this->toArray()
is also working.
Glad it works
Hey, I have set up Laravel Scout with tntsearch according to the documentation. Only thing I did on top was that I set up database queue driver. When I try to search a model with the ::search all I get is empty array.
Controller test function:
Store model:
the result is :
Do you know what can cause this.