Actually nothing is imported to algolia

php artisan scout:import

[OK] All [App\Search\Algolia] records have been flushed.

[OK] All [App\Search\Algolia] records have been imported.

[OK] All [App\Tag] records have been flushed.

Imported [App\Tag] models up to ID: App\Tag::500
Imported [App\Tag] models up to ID: App\Tag::999

[OK] All [App\Tag] records have been imported.

[OK] All [App\Image_Tag] records have been flushed.

Imported [App\Image_Tag] models up to ID: App\Image_Tag::6

[OK] All [App\Image_Tag] records have been imported.

[OK] All [App\Image] records have been flushed.

Imported [App\Image] models up to ID: App\Image::6

[OK] All [App\Image] records have been imported.

Actually nothing is imported to Algolia my indices are empty ???

This is what i have in one of my model

  • <?php
  • namespace App;

  • use Illuminate\Database\Eloquent\Model;

  • use Laravel\Scout\Searchable;

  • use Storage;

  • class Image extends Model

  • {

  • use Searchable;
    
  • public function isPublished()
    
  • {
    
  •     return $this->published_at !== null;
    
  • }
    
  • public function shouldBeSearchable()
    
  • {
    
  •     return $this->isPublished();
    
  • }
    
  • public function toSearchableArray()
    
  • { 
    
  •     $array = $this->toArray();
    
  •     return $array;
    
  • }
    
  • protected $fillable = [
    
  •     'title', 'file_name', 'description', 'category1', 'category2'
    
  • ];
    
  • public function getSrcAttribute(){
    
  •     return Storage::url($this->file_name);
    
  • }
    
  • }

And what I have in my aggregator

  • <?php
  • namespace App\Search;

  • use Algolia\ScoutExtended\Searchable\Aggregator;

  • class Algolia extends Aggregator

  • {

  • /**
    
  •      * The names of the models that should be aggregated.
    
  •      *
    
  •      * @var string[]
    
  •      */
    
  •     protected $models = [
    
  •         \App\Tag::class,
    
  •         \App\Image_Tag::class,
    
  •         \App\Image::class,
    
  •    ];
    
  •    public function shouldBeSearchable()
    
  • {
    
  •     // Check if the class uses the Searchable trait before calling shouldBeSearchable
    
  •     if (array_key_exists(Searchable::class, class_uses($this->model))) {
    
  •         return $this->model->shouldBeSearchable();
    
  •     }
    
  • }
    
  • }

I’m trying to do Multiple Models in One Index

Can you dd('scout.driver') and confirm it’s set to Algolia.

This typically happens when the driver is still set to NullDriver. Sometimes the config was cached and not flushed.

Here’s my scout.php

  • <?php
  • return [

  • /*
    
  • |--------------------------------------------------------------------------
    
  • | Default Search Engine
    
  • |--------------------------------------------------------------------------
    
  • |
    
  • | This option controls the default search connection that gets used while
    
  • | using Laravel Scout. This connection is used when syncing all models
    
  • | to the search service. You should adjust this based on your needs.
    
  • |
    
  • | Supported: "algolia", "null"
    
  • |
    
  • */
    
  • 'driver' => env('SCOUT_DRIVER', 'algolia'),
    
  • /*
    
  • |--------------------------------------------------------------------------
    
  • | Index Prefix
    
  • |--------------------------------------------------------------------------
    
  • |
    
  • | Here you may specify a prefix that will be applied to all search index
    
  • | names used by Scout. This prefix may be useful if you have multiple
    
  • | "tenants" or applications sharing the same search infrastructure.
    
  • |
    
  • */
    
  • 'prefix' => env('SCOUT_PREFIX', ''),
    
  • /*
    
  • |--------------------------------------------------------------------------
    
  • | Queue Data Syncing
    
  • |--------------------------------------------------------------------------
    
  • |
    
  • | This option allows you to control if the operations that sync your data
    
  • | with your search engines are queued. When this is set to "true" then
    
  • | all automatic data syncing will get queued for better performance.
    
  • |
    
  • */
    
  • 'queue' => env('SCOUT_QUEUE', false),
    
  • /*
    
  • |--------------------------------------------------------------------------
    
  • | Chunk Sizes
    
  • |--------------------------------------------------------------------------
    
  • |
    
  • | These options allow you to control the maximum chunk size when you are
    
  • | mass importing data into the search engine. This allows you to fine
    
  • | tune each of these chunk sizes based on the power of the servers.
    
  • |
    
  • */
    
  • 'chunk' => [
    
  •     'searchable' => 500,
    
  •     'unsearchable' => 500,
    
  • ],
    
  • /*
    
  • |--------------------------------------------------------------------------
    
  • | Soft Deletes
    
  • |--------------------------------------------------------------------------
    
  • |
    
  • | This option allows to control whether to keep soft deleted records in
    
  • | the search indexes. Maintaining soft deleted records can be useful
    
  • | if your application still needs to search for the records later.
    
  • |
    
  • */
    
  • 'soft_delete' => false,
    
  • /*
    
  • |--------------------------------------------------------------------------
    
  • | Algolia Configuration
    
  • |--------------------------------------------------------------------------
    
  • |
    
  • | Here you may configure your Algolia settings. Algolia is a cloud hosted
    
  • | search engine which works great with Scout out of the box. Just plug
    
  • | in your application ID and admin API key to get started searching.
    
  • |
    
  • */
    
  • 'algolia' => [
    
  •     'id' => env('ALGOLIA_APP_ID', ''),
    
  •     'secret' => env('ALGOLIA_SECRET', ''),
    
  • ],
    
  • ];

Sorry I meant dd(config('scout.driver')). Please confirm that your driver is algolia when you run the code

Actually when I remove this part

public function isPublished()


* ```
{
  •   return $this->published_at !== null;
    

* ```
}

public function shouldBeSearchable()


* ```
{
  •   return $this->isPublished();
    

* ```
}

it works but, I don’t have an indice who contains all my model’s data together

I fixed the issue by removing all the published function and ```
shouldBeSearchable function like it shows here from the model

  • <?php
  • namespace App;

  • use Illuminate\Database\Eloquent\Model;

  • use Laravel\Scout\Searchable;

  • use Storage;

  • class Image extends Model

  • {

  • use Searchable;
    
  • public function toSearchableArray()
    
  • { 
    
  •     $array = $this->only('file_name','description', 'category1', 'category2');
    
  •     return $array;
    
  • }
    
  • protected $fillable = [
    
  •     'title', 'file_name', 'description', 'category1', 'category2'
    
  • ];
    
  • public function getSrcAttribute(){
    
  •     return Storage::url($this->file_name);
    
  • }
    

}

and i had to add to my aggregator the part missed

  • <?php
  • namespace App\Search;

  • use Algolia\ScoutExtended\Searchable\Aggregator;

  • class Algolia extends Aggregator

  • {

  • /**
    
  •      * The names of the models that should be aggregated.
    
  •      *
    
  •      * @var string[]
    
  •      */
    
  •     protected $models = [
    
  •         \App\Image_Tag::class,
    
  •         \App\Image::class,
    
  •    ];
    
  •    protected $relations = [
    
  •     \App\Image_Tag::class,
    
  •     \App\Image::class,
    
  • ];
    
  • }

and it’s working :slight_smile: