> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Configure index

> Optimize the search experience with Laravel Scout and Algolia Scout Extended.

## Optimize the search experience

### Generate index settings

Performance is important.
On top of that, for a search to be successful, results need to be relevant to users.
Scout Extended provides a `scout:optimize` Artisan command that you may use to optimize the search experience based on information from the `searchable` class:

```sh Command line icon=square-terminal theme={"system"}
php artisan scout:optimize
```

The Artisan command `scout:optimize` tries to generate the settings of your `searchable` class index, but you may need to edit those settings in `config/scout-articles.php`:

```php PHP icon=code theme={"system"}
return [

    /*
    |--------------------------------------------------------------------------
    | Searchable Attributes
    |--------------------------------------------------------------------------
    |
    | Limits the scope of a search to the attributes listed in this setting. Defining
    | specific attributes as searchable is critical for relevance because it gives
    | you direct control over what information the search engine should look at.
    |
    | Supported: Null, Array
    | Example: ["name", "email", "unordered(city)"]
    |
    */

    'searchableAttributes' => ['subject', 'body', 'slug', 'author_name', 'author_email'],

    /*
    |--------------------------------------------------------------------------
    | Custom Ranking
    |--------------------------------------------------------------------------
    |
    | Custom Ranking is about leveraging business metrics to rank search
    | results - it's crucial for any successful search experience. Make sure that
    | only "numeric" attributes are used, such as the number of sales or views.
    |
    | Supported: Null, Array
    | Examples: ['desc(comments_count)', 'desc(views_count)']
    |
    */

    'customRanking' => ['asc(sales_count)', 'desc(views_count)', 'desc(created_at)'],

    // ...
];
```

Feel free to dig further into [all Algolia settings](/doc/api-reference/settings-api-parameters) to optimize the search experience for your users.

### Synchronize index settings

Once you have verified the settings file, all you need to do is synchronize the settings with Algolia using the `scout:sync` Artisan command:

```sh Command line icon=square-terminal theme={"system"}
php artisan scout:sync
```

<Check>
  You can also edit settings using the Algolia dashboard.
  Make sure to apply these settings locally with the `scout:sync` Artisan command if you do this, or your changes will be lost.
</Check>

### Custom settings path

By default, all settings live in `config/scout-{index-name}.php`. You can change this by setting the `settings_path` in the `config/scout.php` configuration file:

```php PHP icon=code theme={"system"}
'algolia' => [
    'id' => env('ALGOLIA_APP_ID', ''),
    'secret' => env('ALGOLIA_SECRET', ''),
    'settings_path' => config_path('customPath'),
],
```

## Custom index name

To customize the index name, you should implement
the [`searchableAs`](https://laravel.com/docs/scout#configuring-model-indexes) method
in your `searchable` class.

<Check>
  If you customize the index name, you **must** include the index prefix by using `config('scout.prefix')`. Without this prefix, the `scout:reimport` won't work as expected.
</Check>

By default, the `searchableAs` method concatenates the `prefix` configuration key defined in `config/scout.php` and the table name. As usual, you can change this behavior:

```php PHP icon=code theme={"system"}
class Article extends Model
{
    use Searchable;

    public function searchableAs()
    {
        return config('scout.prefix').'my_custom_name';
    }
}
```

### Per-environment index name

Scout reads the prefix from your environment variables. If you need different indices for each environment, you should define a different `PREFIX` in your `.env` file.

```dotenv .env icon=lock-keyhole theme={"system"}
SCOUT_PREFIX=demo_PROD_
```
