Support » Plugin: WP Search with Algolia » Managing app IDs between environments

  • Resolved Jon Dingman

    (@jdingman)


    I’m running into an issue when pushing code between environments and data indexing.

    I’m using LocalWP.

    Is there a best practice to efficiently manage environments and indexes and application IDs between environments?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Looks like these can be defined as constants in your wp-config and they’ll be used first before the values in the options page.

    ALGOLIA_APPLICATION_ID
    ALGOLIA_SEARCH_API_KEY
    ALGOLIA_API_KEY
    ALGOLIA_INDEX_NAME_PREFIX

    You could use those with different values based on your environment.

    That should work, thank you!

    @tw2113 additionally, I have my own search.js file which I’m loading up with some customizations, since I’m not using the native search functionality. I built my own and connected it to Algolia.

    The problem I’m trying to solve is that, at the moment, the app IDs and keys are hard coded into search.js (file I created), is there a better way to manage this across environments?

    const searchClient = algoliasearch( “8D1B221KTYC”, “235cde75a1b422212811408d39ac8d” );

    const search = instantsearch( {
    indexName: “localnew_searchable_posts”,
    searchClient,
    searchFunction( helper ) {
    // Ensure we only trigger a search when there’s a query
    if ( helper.state.query ) {
    helper.search();
    }
    },
    } );

    Also to localize the indexName so it’s for that particular environment.

    Thoughts?

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Why not make use of https://developer.wordpress.org/reference/functions/wp_add_inline_script/ + any dev-specific PHP constants for this. you could define a new constant for the indexName along side your API keys, and then use that function above to grab the constants and get them output to the page. Then they would be in scope for the custom search file.

    @tw2113 I’m running into separate issues now with the prefix you mentioned above, I noted it on github.

    https://github.com/WebDevStudios/wp-search-with-algolia/issues/93

    Ah I think I know what’s going on actually. I have just the prefix in the code, and I need to add “_searchable_posts” to it.

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    I think you have this covered again 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.