Disabling Search Index Auto Updating on Entry Save #5316
-
Does Statamic 3 have the option to control the auto indexing of search anymore? I haven't been able to find anything about it. I have Algolia setup totally fine, my issue is that I don't want Statamic to update the record within Algolia on every save of an entry. I'd rather do it manually with the command php please search:update. In Statamic 2 there was a setting in site/settings/search.yaml with auto_index: true which would then in statamic/bundles/Search/SearchListener.php either submit the updated change to Algolia (or chosen search engine) or not on save of the page/entry (https://v2.statamic.com/knowledge-base/performance#disable-search-autoindexing). There doesn’t appear to be documentation on this within Statamic 3 that I can find. I assume that there should be a similar function to the insert function within SearchListener.php or whatever the equivalent is within Statamic 3. Might help to find it within Statamic; in Statamic 2 the function which is doing the search update is (in SearchListener.php):
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Why? |
Beta Was this translation helpful? Give feedback.
-
We have migrated to Statamic 3 and are using the headless version of it with Nuxt, which means that we deploy just a front end build rather than with the CMS as it's a static site. We also have a situation with a site where we don't control the deployment/server of the final live site and merely provide the static built site to be deployed. As a result of this the CMS where edits are done are on our hosted servers. We have a search index for that CMS build in order to test etc but also have a separate search index for the deployed front end. Otherwise the changes that are being made within the CMS and haven't been deployed yet will show up in search results on the live environment (due to all search indices being updated on save) - we obviously don't want this misalignment and don't want to potentially expose non published content within search results. So ideally we are able to turn off the auto indexing, as Statamic 2 had, and we can control manually using the If there's another/better way to manage this obviously open to that too, with it ideally being as automated as possible. |
Beta Was this translation helpful? Give feedback.
-
It will always update. But sounds like you have a bit of a custom situation. You can override the event subscriber. In your AppServiceProvider, add this to $this->app->extend(UpdateItemIndexes::class, function ($original) {
return config('statamic.search.auto_update')
? $original
: new DontUpdateItemIndexes;
}); and create the <?php
namespace App;
class DontUpdateItemIndexes
{
public function subscribe($event)
{
// do nothing
}
} Then add the new config key, which you can control however makes sense for you, in this case through an // config/statamic/search.php
<?php
return [
'auto_update' => env('SEARCH_AUTO_UPDATE', false),
// ...
]; |
Beta Was this translation helpful? Give feedback.
-
Thanks for the solution @jasonvarga! The frontend consists of just static html files (SSG). I want the search index to be based on the same content state as when building the statics. Therefore I want to update the search index only when building the frontend. |
Beta Was this translation helpful? Give feedback.
It will always update. But sounds like you have a bit of a custom situation. You can override the event subscriber.
In your AppServiceProvider, add this to
register
.and create the
DontUpdateItemIndexes
class which is basically a dummy override.Then add the new config key, which you can control however makes sense for you, in this case through an
.env
var.