Algolia - Zendesk Integration - Force Community Topic List Page to use Zendesk instead of Algolia

Hello,

We are using the Algolia/Zendesk integration and the search results are great!

However, the integration does not index Community Forum posts at this time.

What we were looking to do is to use Algolia Instant Search and Auto-Complete for our main search results, but use the Zendesk stock search on our Community Topics page.

Does anyone have some advice?

I’m not entirely sure what you mean by “stock search”.
Are you talking about Zendesk’s autocomplete provided with {{ search instant=true }}?

If this is the case, the integration will automatically hide Zendesk’s autocomplete and add a small message in your console saying that you should remove it.

But you can actually keep it, and conditionnaly activate Algolia on the pages you want:

  // Get path without /hc/en-us
  var pathWithoutLocale = '/' + window.location.pathname.split('/').slice(3).join('/')
  console.log("pathWithoutLocale: " + pathWithoutLocale);

  // Use our search on every page except /community/topics
  if (pathWithoutLocale !== '/community/topics') {
    algoliasearchZendeskHC({
      applicationId: 'xxx',
      apiKey: 'xxx',
      subdomain: 'xxx'
    });
  }

Hi Jerska,

Thank you for your assistance. I was referring to the Instant Search.

We added the code to our Document Head and the Autocomplete feature is no longer functioning on the Community Topics Page. However, search results after hitting enter are still going to the Algolia Instant Search and not the Zendesk search results.

Is there a way to disable the use of Instant Search on any pages that contain /community/topics in the URL (such as https://support.neoncrm.com/hc/en-us/community/topics)?

<script type="text/javascript">
  var pathWithoutLocale = '/' + window.location.pathname.split('/').slice(3).join('/')
  console.log("pathWithoutLocale: " + pathWithoutLocale);
  if (pathWithoutLocale !== '/community/topics') {
  algoliasearchZendeskHC({
    applicationId: 'XXX',
    apiKey: 'XXX',
    subdomain: 'XXX',
  });
  }
</script>

Oh, I understood it the other way around.
You can definitely revert the piece of code I shared with you.

Here, the issue is that you want to use the same search page, but with a different behavior depending on the URL it comes from.
This is definitely not something we’d recommend, as it can easily be confusing for users to get a non-explicit behavior.

What happens if someone shares the URL afterwards? Should it show it display with Algolia, or use the same layout as the one the user saw?

What we usually recommend when you use the Community feature of a Zendesk Help Center, is to simply disable the instant search. As a result, users have Algolia for a quick access, but can still press Enter to find community topics.

This is easily done instantsearch.enabled (see our documentation):

<script type="text/javascript">
  algoliasearchZendeskHC({
    applicationId: 'XXX',
    apiKey: 'XXX',
    subdomain: 'XXX', // <- Don't forget to add a comma at the end of this line
    instantsearch: {
      enabled: false
    }
  });
</script>

Hi Jerska,

Thank you. We were using the instantsearch parameter, but disabling the instantsearch would remove your excellent search results from being used in our Support Center (outside of using autocomplete, of course).

Search results are not typically shared, only direct URLs to articles.

Is there any code that we can use that would not use Algolia’s instant search on any page that contains /community/topics ?

Thanks for the compliment on the quality of our search.
The main issue here is that we’re not testing the value of the current page, but of the previous one – because searching on / or /community/topics will redirect you to the same /search page.

This is usually not recommended in web development, for the reason I gave above.

  • Someone copy pasting the URL in a new tab will have different results
  • A link to this URL will show different results
  • A browser crash -> restart might bring different results

But if that’s fine for you, here’s the logic you could use for this:

  var useInstantsearch = true;
  try {
    // Get referrer
    var referrer = new URL(window.referrer);
    // Get path without /hc/en-us
    var pathWithoutLocale = '/' + referrer.pathname.split('/').slice(3).join('/');
    // Activate our instantsearch when coming from non-community pages
    useInstantsearch = Boolean(pathWithoutLocale.match(/\/community\//))
  } catch (e) {
    // If we couldn't use the referrer, default to Zendesk's default search
    useInstantsearch = false;
  }

  // Use our search on every page except /community/topics
  if (pathWithoutLocale !== '/community/topics') {
    algoliasearchZendeskHC({
      applicationId: 'xxx',
      apiKey: 'xxx',
      subdomain: 'xxx',
      instantsearch: {
        enabled: useInstantsearch
      }
    });
  }

[This code is untested, but has the main logic]

Thank you again for your help!

Should this entire code replace what is currently being used in the document_head ZD file?