Skip to content

Commit a03b68d

Browse files
Add explanation for index-settings for Algolia in Scout (#10138)
* Add explanation for index-settings for Algolia in Scout * docs: add focus on why you might want to deploy scout index configuration from source code * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent cc3a852 commit a03b68d

File tree

1 file changed

+52
-9
lines changed

1 file changed

+52
-9
lines changed

scout.md

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ For more information regarding Meilisearch, please consult the [Meilisearch docu
123123

124124
In addition, you should ensure that you install a version of `meilisearch/meilisearch-php` that is compatible with your Meilisearch binary version by reviewing [Meilisearch's documentation regarding binary compatibility](https://github.com/meilisearch/meilisearch-php#-compatibility-with-meilisearch).
125125

126-
> [!WARNING]
126+
> [!WARNING]
127127
> When upgrading Scout on an application that utilizes Meilisearch, you should always [review any additional breaking changes](https://github.com/meilisearch/Meilisearch/releases) to the Meilisearch service itself.
128128
129129
<a name="typesense"></a>
@@ -281,6 +281,49 @@ Some search engines such as Meilisearch will only perform filter operations (`>`
281281
];
282282
}
283283

284+
<a name="configuring-indexes-for-algolia"></a>
285+
#### Configuring Index Settings (Algolia)
286+
287+
Sometimes you may want to configure additional settings on your Algolia indexes. While you can manage these settings via the Algolia UI, it is sometimes more efficient to manage the desired state of your index configuration directly from your application's `config/scout.php` configuration file.
288+
289+
This approach allows you to deploy these settings through your application's automated deployment pipeline, avoiding manual configuration and ensuring consistency across multiple environments. You may configure filterable attributes, ranking, faceting, or [any other supported settings](https://www.algolia.com/doc/rest-api/search/#tag/Indices/operation/setSettings).
290+
291+
To get started, add settings for each index in your application's `config/scout.php` configuration file:
292+
293+
```php
294+
use App\Models\User;
295+
use App\Models\Flight;
296+
297+
'algolia' => [
298+
'id' => env('ALGOLIA_APP_ID', ''),
299+
'secret' => env('ALGOLIA_SECRET', ''),
300+
'index-settings' => [
301+
User::class => [
302+
'searchableAttributes' => ['id', 'name', 'email'],
303+
'attributesForFaceting'=> ['filterOnly(email)'],
304+
// Other settings fields...
305+
],
306+
Flight::class => [
307+
'searchableAttributes'=> ['id', 'destination'],
308+
],
309+
],
310+
],
311+
```
312+
313+
If the model underlying a given index is soft deletable and is included in the `index-settings` array, Scout will automatically include support for faceting on soft deleted models on that index. If you have no other faceting attributes to define for a soft deletable model index, you may simply add an empty entry to the `index-settings` array for that model:
314+
315+
```php
316+
'index-settings' => [
317+
Flight::class => []
318+
],
319+
```
320+
321+
After configuring your application's index settings, you must invoke the `scout:sync-index-settings` Artisan command. This command will inform Algolia of your currently configured index settings. For convenience, you may wish to make this command part of your deployment process:
322+
323+
```shell
324+
php artisan scout:sync-index-settings
325+
```
326+
284327
<a name="configuring-filterable-data-for-meilisearch"></a>
285328
#### Configuring Filterable Data and Index Settings (Meilisearch)
286329

@@ -400,7 +443,7 @@ Enabling this feature will also pass the request's IP address and your authentic
400443
<a name="database-engine"></a>
401444
### Database Engine
402445

403-
> [!WARNING]
446+
> [!WARNING]
404447
> The database engine currently supports MySQL and PostgreSQL.
405448
406449
If your application interacts with small to medium sized databases or has a light workload, you may find it more convenient to get started with Scout's "database" engine. The database engine will use "where like" clauses and full text indexes when filtering results from your existing database to determine the applicable search results for your query.
@@ -441,7 +484,7 @@ public function toSearchableArray(): array
441484
}
442485
```
443486

444-
> [!WARNING]
487+
> [!WARNING]
445488
> Before specifying that a column should use full text query constraints, ensure that the column has been assigned a [full text index](/docs/{{version}}/migrations#available-index-types).
446489
447490
<a name="collection-engine"></a>
@@ -496,7 +539,7 @@ If you would like to modify the query that is used to retrieve all of your model
496539
return $query->with('author');
497540
}
498541

499-
> [!WARNING]
542+
> [!WARNING]
500543
> The `makeAllSearchableUsing` method may not be applicable when using a queue to batch import models. Relationships are [not restored](/docs/{{version}}/queues#handling-relationships) when model collections are processed by jobs.
501544
502545
<a name="adding-records"></a>
@@ -529,7 +572,7 @@ Or, if you already have a collection of Eloquent models in memory, you may call
529572

530573
$orders->searchable();
531574

532-
> [!NOTE]
575+
> [!NOTE]
533576
> The `searchable` method can be considered an "upsert" operation. In other words, if the model record is already in your index, it will be updated. If it does not exist in the search index, it will be added to the index.
534577
535578
<a name="updating-records"></a>
@@ -625,7 +668,7 @@ Sometimes you may need to only make a model searchable under certain conditions.
625668

626669
The `shouldBeSearchable` method is only applied when manipulating models through the `save` and `create` methods, queries, or relationships. Directly making models or collections searchable using the `searchable` method will override the result of the `shouldBeSearchable` method.
627670

628-
> [!WARNING]
671+
> [!WARNING]
629672
> The `shouldBeSearchable` method is not applicable when using Scout's "database" engine, as all searchable data is always stored in the database. To achieve similar behavior when using the database engine, you should use [where clauses](#where-clauses) instead.
630673
631674
<a name="searching"></a>
@@ -682,7 +725,7 @@ The `whereNotIn` method verifies that the given column's value is not contained
682725

683726
Since a search index is not a relational database, more advanced "where" clauses are not currently supported.
684727

685-
> [!WARNING]
728+
> [!WARNING]
686729
> If your application is using Meilisearch, you must configure your application's [filterable attributes](#configuring-filterable-data-for-meilisearch) before utilizing Scout's "where" clauses.
687730
688731
<a name="pagination"></a>
@@ -719,7 +762,7 @@ Of course, if you would like to retrieve the pagination results as JSON, you may
719762
return Order::search($request->input('query'))->paginate(15);
720763
});
721764

722-
> [!WARNING]
765+
> [!WARNING]
723766
> Since search engines are not aware of your Eloquent model's global scope definitions, you should not utilize global scopes in applications that utilize Scout pagination. Or, you should recreate the global scope's constraints when searching via Scout.
724767
725768
<a name="soft-deleting"></a>
@@ -739,7 +782,7 @@ When this configuration option is `true`, Scout will not remove soft deleted mod
739782
// Only include trashed records when retrieving results...
740783
$orders = Order::search('Star Trek')->onlyTrashed()->get();
741784

742-
> [!NOTE]
785+
> [!NOTE]
743786
> When a soft deleted model is permanently deleted using `forceDelete`, Scout will remove it from the search index automatically.
744787
745788
<a name="customizing-engine-searches"></a>

0 commit comments

Comments
 (0)