External search services provide advanced features such as typo tolerance or custom ranking of the search results. They also often come with SDKs and tutorials to help you integrate them within your app.
Flow between the search service and your app
When you need to add a search to your app, an external search service usually fits the bill. After you complete the initial integration with the service and add logic for reacting to content changes, you get a search with an index that’s automatically updated.When integrating an external search service, you need to:
Design the index. Ask yourself what data and in what structure you want in the index.
Create a service that reacts to content changes and propagates them to the index.
Initialize the index with initial data.
1. Design the index
Define what content you want to search for. You might have multiple types of content like articles, products, and more. Think about the search experience you want to build.What do you include in the index? Consider the following guidelines:
Include the data you want to display in the search results. This avoids fetching content items for each search result.
If you want a faceted search, include any metadata you want to use for facets. Consider all information that might be relevant such as taxonomies, languages, collections, and so on.
If your searchable piece of content is made of multiple linked content items, include the data of the linked items so that your search record is complete.
2. Create a service that reacts to content changes
To ensure the search index stays up to date, you need to react to the content changes made in your Kontent.ai project. You can automate the process of updating your search index by either setting up webhooks and responding to notifications, or asking for the latest changes at your own pace with Sync API.
With webhooks, you provide a URL such as https://myapp.com/update-search-index, and you get notifications to that URL right after any content changes. Based on the notifications, you decide whether to add new content or remove records from your search index.
With Sync API, you ask the API if there were any recent changes to the content you’re interested in. If there are changes to the process, you decide whether to add new content or remove records from your search index. And after a while, you ask again.
Syncing changes in linked items
If there’s a change in a linked content item that isn’t searchable on its own, you first need to check if the item belongs to any searchable content item.To find which search records to update, you need to query your search index for the content item’s identifier. Once you know which records are affected, you can update them with fresh content.
3. Initialize the index
If you already have content items you would like to have in the search index, you will need to insert them into the index before you can use it. It can be similar in functionality to the endpoint that syncs changes, but it needs to go through all items in your Kontent.ai project and sync all of them.You’ll call this endpoint only manually when initializing the index and occasionally when you want to rebuild the index from scratch. For example, when you want to change the data saved in the index for each item.
Examples of external search integration
You can start your integration with one of our example integrations.For more integration examples, check the following guides.
Searching Content with Algolia – walks you through adding an Algolia search service into an ASP.NET MVC application and updating the search index in reaction to webhook messages.
Implementing search with Gatsby and Algolia – guides you to bring relevance, typo-tolerance or term-boosting with Algolia to a website built on Gatsby, where the built-in filter isn't sufficient.
If you want to build a simple index over your site’s content quickly, you can use a service (such as Algolia crawler) that automatically crawls your site and builds a search index over its content. It is less flexible than a manually designed index but can be sufficient in certain cases with less work.