Integrate an external search service
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.
External search integration overview
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.
- Include the identifiers of all content items to be able to update the index when content items change.
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 setting up webhooks and responding to notifications:- Provide a URL such as
https://myapp.com/update-search-index
, and get notifications to that URL right after any content changes. - Based on the notifications, decide whether to add new content or remove records from your search index.