xevioso
Forum Replies Created
-
For future reference for anyone else who is in this situation, here’s the final code I used:
if (!empty($_ENV['PANTHEON_ENVIRONMENT'])) {
if ($_ENV['PANTHEON_ENVIRONMENT'] === 'live') {
define('ALGOLIA_INDEX_NAME_PREFIX', 'wp_'); // Live environment
} else {
define('ALGOLIA_INDEX_NAME_PREFIX', 'wp_' . $_ENV['PANTHEON_ENVIRONMENT'] . ''); // Non-live environments } } else { // Fallback to a default prefix if the environment is not defined define('ALGOLIA_INDEX_NAME_PREFIX', 'wp_development'); // Default prefix for non-Pantheon environments
}Which checks to see if the environment is live; if it is, the prefix remains “wp_”;
If it is any other defined environment, it sets the prefix to be “wp_environmentname_” , including multidev, autopilot, and local environments (like my Lando local version.)
Thank you very much for your patience and assistance.
–Jeremy
Hello, Michael.
I’m about to implement this, but I wanted to run this by you.
If I set the following code in wp-config.php:
if (!empty($_ENV['PANTHEON_ENVIRONMENT'])) {
define('ALGOLIA_INDEX_NAME_PREFIX', $_ENV['PANTHEON_ENVIRONMENT'] === 'live' ? 'wp_' : 'wp_development_');
} else {
// Fallback to a default prefix if the environment is not defined
define('ALGOLIA_INDEX_NAME_PREFIX', 'wp_development_');
}This should, in theory, set the prefix to be “wp_” if it is the “live” environment; otherwise the prefix is set to be “wp_development” for all other environments.
This should then, in theory, overwrite the prefix set in the plugin settings for Index Name Prefix for any given envirionment.
Also In theory, then reindexing content from the live environment will now only pull content into the main index from the live environment, as it will be the only environment with the index prefix set to “wp_”, and so search results on the live site will only display results from that index.
Is this correct? And what then would happen if I attempted to reindex the site from a non-live environment?
Thanks Michael.
OK, so, this part of that page specifies how to target the live environment:
https://docs.pantheon.io/guides/environment-configuration/environment-specific-config#add-configuration
So my question is, what would be the best practice here with the WP plugin in a live-specifics-configs.php file? If I do something likeif(is_plugin_active($plugin)) {
deactivate_plugins($plugin);
}In all environments other than live, where
#List Development Plugins
$plugins = array(
'wp-search-with-algolia/algolia.php'
);Is set, in theory that would only disable the WP Search With Algolia plugin in all non-live environments… right?
Would it be better for me to maybe just set the API key or Application ID to null or change the index name prefix to be something other than “wp_” in all non-live environment? And then just re-index the site?
Hello. Funny you should mention this; I’ve still been struggling to get this issue corrected. However, I had a support ticket open with Pantheon, and they responded yesterday with a reference to this page:
https://docs.pantheon.io/guides/environment-configuration/environment-specific-config
I’m wondering how I will be able to use the constants you’ve listed on your constants page in the various environments to solve this; I plan on having a deeper look shortly, but I’m hoping their link will provide me with what I need.
Hello. Not quite sure I understand.
So the prefix is set to be “wp_” in our production environment in Algolia settings. We create multidev environments for testing purposes regularly, usually cloned from production, so it’s not feasible for us to change this manually each time for new environments to be something other than wp_.
So if I set the below, does this overwrite whatever I have set in WP Search with Algolia Settings for index prefix? And if I clone down this code to other environments, won’t it just set the prefix for those environments to be that as well?<?php // […] define( 'ALGOLIA_INDEX_NAME_PREFIX', 'tpl_prod'); // […]I guess I am unclear on how I would differentiate the prefixes in multiple environments, and only allow reindexing from just the one that I want.
In an ideal world in this instance, there would be a field in the settings that would allow you to add a set of domains, and then when you do a bulk re-index, it only indexes posts from those domains.
Thank you for your help.
- This reply was modified 2 years, 8 months ago by xevioso.