WebDevStudios / wp-search-with-algolia

Improve search on your site. Autocomplete is included, along with full control over look, feel and relevance.
https://wordpress.org/plugins/wp-search-with-algolia/
146 stars 55 forks source link

Is there a filter that will prevent local changes from affecting the prod index? #389

Closed GioAceto closed 12 months ago

GioAceto commented 12 months ago

We have multiple indexes for several sites. When we make changes locally or in our development environment, those indexes are being modified after saving. Is there a way to prevent that? We only want those indexes modified in production. We can't have separate prod and dev indexes because we have an aggregation script that runs and combines all of those indexes into a master index that our main site uses.

It doesn't seem like you have much documentation about what each filter does in detail so I'm not sure if one of them could solve this issue.

Here's what I tried, but this seems like instead of preventing the changes from being indexed, it's preventing the whole page from being indexed:

function disable_algolia_indexing() {
    $site_url = $_SERVER['HTTP_HOST'];

    // Check if the site URL is local
    if (strpos($site_url, 'example.com') === false) {
        // Disable Algolia indexing
                return false;
    }
}

add_filter('algolia_should_index_searchable_post', 'disable_algolia_indexing');

We're hoping we could swap out this filter with one that would disable live updates.

Thanks!

tw2113 commented 12 months ago

Not really on a filter like this, because it would essentially need to prevent indexing of all sorts across the install.

Instead I'd recommend checking out our available constants, most specifically the ALGOLIA_INDEX_NAME_PREFIX constant. This can be defined in your wp-config.php file and can be different for various environments. That way say local_ would get their own indexes in the application, and prod could be left with the default wp_ or get its own like prod_. Thus changes made in non-prod environments don't make it into prod.

GioAceto commented 12 months ago

This looks to be exactly what we need. Thanks for the help!

tw2113 commented 12 months ago

Welcome.