How to manually enable Algolia / call algoliasearchZendeskHC

Hi, I have Algolia running on a Zendesk Help Center, and while it seems to be working well for external users, the lack of internal article indexing breaks it for other types of users (like internal agents, or customers who have access to restricted content)

It looks like algolia.js is imported in head, and then algoliasearchZendeskHC() is called with our custom parameters to actually enable it. My plan was to remove this second call from the doc head, and only call it only once I’ve been able to determine the user should see the enhanced Algolia search.

My problem is, no matter how I manually call the algoliasearchZendeskHC function, it hides the search box altogether instead of enabling Algolia. I’ve tried calling the function on doc ready, or even from the JS console, but still have not gotten this to work.

Is there a reliable way to manually ‘enable’ Algolia after the .css and .js have been loaded in the doc head? [edit: manually ‘disabling’ Algolia after it’s loaded would work just as well for this situation]

Unfortunately, our Zendesk integration only indexes public articles for security reasons.
You can learn a bit more about why here: https://community.algolia.com/zendesk/documentation/#indexing-private-articles .
The basic issue is that you’ll have to provide an API key with full access in your code, so even if you can indeed filter, anyone could grab the API key and relaunch the search without the filters to find your internals tickets.

However, both our crawler and front-end code are open-source.
If you really want to, you can index them by modifying and running the crawler manually on one of your machines. See https://github.com/algolia/algoliasearch-zendesk/ .
The code to check if an article is public is this one: https://github.com/algolia/algoliasearch-zendesk/blob/9360a8d336541df219303a7c4460c25901cf325e/crawler/types/article.rb#L22-L28 .

You should be able to let only the loads of our CSS and JS file, remove the algoliasearchZendeskHC() call, save, load the page, and run it from the console. If this doesn’t work, can you please send us a link to your Help Center with the two files loaded but without the call to algoliasearchZendeskHC in your Document Head?
Also, if you could provide your algoliasearchZendeskHC block, this would help. :slight_smile:

Hi Jerska,

Thanks for the info. Makes sense about the inability to index private articles - and I think that would still be the intended use for us (so we’d revert to Zendesk’s built-in search only for users who have access to private articles)

support.formlabs.com is our help center. I’ve currently disabled Algolia by commenting out the algoliasearchZendeskHC() function - you should be able to view it’s source/parameters in the document head.

Currently, if I load the CSS and JS in the doc head, but call algoliasearchZendeskHC() later (with the same parameters), the main search bar disappears, and is not replaced with anything. I’ve noticed that when this happens, a new style rule is added <head> that sets #query { visibility: hidden !important; }, which I didn’t see added when the function is called directly from the doc head.

Sorry about the delay in my answer, I’ve missed the notification!
So about your issue, I was unsure about what could be happening. Fortunately, debugging it was fairly easy.

In my code, I’m plugging the render on the DOM Content Ready event. However, when you call it after the page has loaded, this event has already fired.

I’ve added some code to handle both cases and deployed a feature update.
See https://github.com/algolia/algoliasearch-zendesk/blob/master/CHANGELOG.md#2150-2017-07-12-1 .
If you refresh without cache, you should now be able to do what you want!

The CDN we’re using will take some time to propagate the change. In the meantime, you can replace in the two links (CSS and JS) the /2/ by /2.15/ and try again!

The reason of the hiding is that by default, we hide the autocomplete input on the instantsearch page.

So when the script loads, we hide the autocomplete input anyway, and when we know that the autocomplete should be used and is ready, then we un-hide it.