0

When I import my model to Algolia I change the ObjectId to the value of another field. But it seems when I call delete() on my object it doesn't remove it from Algolia. To be more clear here is an example:

User{ id, email name }

Algolia User {objectId :email,name}

is there a way to solve this issue? Does scout have a function to overwrite the original delete function similiar to toSearchableArray?

EDIT: I have requested this feature on Scout GitHub for anyone interested

Hirad Roshandel
  • 2,175
  • 5
  • 40
  • 63

3 Answers3

1

I ended up using Algolia SDK to manually delete it.

    $client = new \AlgoliaSearch\Client(env('ALGOLIA_APP_ID'), env('ALGOLIA_SECRET'));
    $index = $client->initIndex('index_name');
    $index->deleteObject($model->email);
Hirad Roshandel
  • 2,175
  • 5
  • 40
  • 63
1

I think the easiest way is to create a custom driver and extend the AlgoliaEngine.

I wrote some docs about it: https://www.algolia.com/doc/api-client/laravel/extending-scout#extending-algolias-driver

Julien Bourdeau
  • 1,193
  • 11
  • 17
0

I guess that you have problem in your model. Go along convention:

namespace App;

use Illuminate\Database\Eloquent\Model;

class Flight extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'my_flights';
}

More: https://laravel.com/docs/5.5/eloquent#eloquent-model-conventions

Here you have similar issue: https://discourse.algolia.com/t/model-import-problem/3300/2

Adam Kozlowski
  • 5,606
  • 2
  • 32
  • 51
  • It deletes it from database so that shouldn't be the issue. – Hirad Roshandel Mar 01 '18 at 16:51
  • But if you change the object id (primary key) to store it in Algolia, why not also change the primary key of the object in Laravel? `protected $primaryKey = '{object}_id'` then you send it to Algolia – Kenny Horna Mar 01 '18 at 17:21
  • @HCK I understand and your point is valid. However, at this point, I have to go through major refactoring to change that. – Hirad Roshandel Mar 01 '18 at 18:01