DocumentationLogin
Enterspeed logo

Search engine integration

Enterspeed patterns

Search functionality is a requirement for most websites today as it helps users find the right product, article etc. Especially on websites with lots of pages or a deep hieratical content structure. Thus, a good search engine is also one of the most important navigational features on a website.

Building a strong search engine that serves fast and relevant results is, however, a huge task and probably not something you want to build yourself. Instead, you opt for an existing search engine such as Algolia, Cludo, or any other search engine out there.

How to implement this pattern

Feed your search engine with data: There are generally two strategies for feeding a search engine with your data: 1) Ingesting data through an API and 2) Letting the search engine crawl your website. 

Ingesting your data through an API requires you to write some kind of integration. Should data be ingested once a day, or should individual pieces of content be ingested as soon as they are updated in your source system (CMS, PIM, ...)?

Making the search engine crawl your website is typically an easier solution than building an API integration. However, it often requires you to add extra metadata to your HTML output because the search engine need additional information such as last updated, category, tagging etc. Also, content doesn't get updated in your search index immediately during website crawling. Crawling usually runs once an hour or even only once a day.

Add the search functionality on your website: Some search engines provide a script for the search field and the search result view that you can insert on your website. This is easy and fast to do. However, if you want the look and feel to be fully integrated on your website, you often build the search field and search result yourself using an API to the search engine.

Monitor your search results and tweak your search engine: Once your search is live, it's important to monitor your search results. If many users don't click on a search result after doing a search, or if they navigate to pages 2, 3 or 4 before clicking a search result, it could be a signal to you that the search results are not relevant or good enough.

An observation like this tells you that you probably need to tweak your search engine. Maybe you need to add extra metadata, like aliases, or maybe you need to boost the importance of some fields or whatever options you have with your search engine.

How to implement with Enterspeed

The first thing you need to do is to send your data to Enterspeed using our Ingest API. The following code snippet is a JavaScript example using our Ingest REST API, but you can also use our .NET Enterspeed Source SDK.

1// Ingest example in JavaScript using the Enterspeed Ingest REST API
2
3const ingestToEnterspeed = async (sourceEntity) => {
4  const url = `https://api.enterspeed.com/ingest/v2/${sourceEntity.id}`;
5  const response = await fetch(new Request(url), {
6    method: "post",
7    headers: {
8      "Content-Type": "application/json; charset=UTF-8",
9      "X-Api-Key": "[EnterspeedApiKey]",
10    },
11    body: JSON.stringify(sourceEntity)
12  });
13  return response.json();
14};
15
16const mySourceEntity = {
17  id: 12, 
18  url: 'https://mysite.com', 
19  type: 'contentPage', 
20  properties: { title: 'My headline' }
21};
22
23ingestToEnterspeed(mySourceEntity)
24  .then((data) => {
25    console.log(data);
26  });

Then you use Enterspeed's schemas to model the ingested data into the desired output model. In the below example, a 1:1 mapping of the ingested source entity is done in the properties function.

The important thing In the Enterspeed schema below is the actions function. Here, we define that the generated view from this schema should be sent to Algolia. This means that the view is both available from the Enterspeed Delivery API through the URL defined in the routes function and available in Aloglia for searching without you having to build any integration to Algolia.

If you use other search engines or other types of software that we currently don't have a direct integration for, you can always use our webhook as the destination.

1// contentPage schema with a destination action to send the view to Algolia
2
3/** @type {Enterspeed.FullSchema} */
4export default {
5  triggers: function(context) {
6    context.triggers('cms', ['contentPage'])
7  },
8  routes: function(sourceEntity, context) {
9    context.url(sourceEntity.url)
10  },
11  actions: function(sourceEntity, context) {
12    context.destination('algolia')
13  }
14  properties: function (sourceEntity, context) {
15    return sourceEntity.properties
16  }
17}

To do the search in the frontend application, you can use Algolia's Search REST API. Here's an example in JavaScript:

1// JavaScript example of how to call Algolia search API
2
3export const searchAlgolia = async (searchTerm) => {
4  const url = `https://[AlgoliaApplicationId]-dsn.algolia.net/1/indexes/[AlgoliaIndexName]`;
5  const response = await fetch(new Request(url), {
6    method: "post",
7    headers: {
8      "Content-Type": "application/json; charset=UTF-8",
9      "X-Algolia-Application-Id": "[AlgoliaApplicationId]",
10      "X-Algolia-API-Key": "[AlgoliaApiKey]",
11    },
12    body: JSON.stringify({ "params": `query='${searchTerm}'&hitsPerPage=10` })
13  });
14  return response.json();
15};

Additional resources

Ready to try out Enterspeed? 🚀

Start combining & connecting your services today

Product

Why Enterspeeed?Use casesBuild vs. buyIntegrations

Company

Partners ☕ Let's talk!About UsContact UsTerms of ServicePrivacy PolicySecurity
Enterspeed logo

© 2020 - 2024 Enterspeed A/S. All rights reserved.

Made with ❤️ and ☕ in Denmark.