Kontent.ai
Copyright © 2023 Kontent.ai. All rights reserved.
  • Web
  • Privacy policy
  • Cookies policy
  • Consent settings
  • Security
  • GDPR
  • Documentation
  • API reference
  • Product updates
Kontent.ai Learn
  • Plan
  • Set up
  • Model
  • Develop
  • Create

Integrate an external search service

Is this page helpful?
Complete and continue
  • Sign in
  • Jiri Lojda, Jan Cerman
    4 minutes
    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:
    1. Design the index. Ask yourself what data and in what structure you want in the index.
    2. Create a service that reacts to content changes and propagates them to the index.
    3. 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.
    • Include the identifiers of all content items to be able to update the index when content items change.
    To find more about designing a search index, check Algolia's guide about preparing data for a search index.

    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.

    Algolia

      • Searching and indexing content with Algolia – an example integration with more detail on synchronizing Kontent.ai with an external search index.
      • 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.
      • Algolia integration in Express.js sample app – shows you a working JavaScript sample app that uses Algolia for search.
      • 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.

    Azure Search

      • How to Integrate Azure Cognitive Search with Kontent.ai – shows how you can use Azure Cognitive Search with webhooks in a .NET web app.

    Hawksearch

      • Hawksearch's Integration Will Refine Your Search Experience – presents how to connect Hawksearch to Kontent.ai by showing how to request and display search results.
    What's next?
    Consider in-app filtering
    If your project is smaller, your app can load all content and use in-app filtering for search.

    See the diagram on https://viewer.diagrams.net?lightbox=1&nav=1#Uhttps://github.com/JiriLojda/kontent-ai-learn-diagrams/raw/search_guide_diagrams/integrations/search/flattening.drawio

    See the diagram on https://viewer.diagrams.net?lightbox=1&nav=1#Uhttps://github.com/JiriLojda/kontent-ai-learn-diagrams/raw/search_guide_diagrams/integrations/search/updateReferencedItems.drawio

    • Develop with Kontent.ai
    • Hello World
    • Hello Web Spotlight
    • Run a sample app
    • Build apps
    • Decide navigation and URLs
    • Environments
    • Get Developer Certification

    See the diagram on https://viewer.diagrams.net?lightbox=1&nav=1#Uhttps://raw.githubusercontent.com/JiriLojda/kontent-ai-learn-diagrams/search_guide_diagrams/integrations/search/searchOverview.drawio

    External search integration overview
    • Overview
    • Integrate search
    • Translation management systems
    • Automate content updates with webhooks
    Algolia
    Recombee
    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.
    Search provider
    Recommendation engine
    • External search services
    • In-app filtering
  • Flow between the search service and your app
  • 1. Design the index
  • 2. Create a service that reacts to content changes
  • 3. Initialize the index
  • Examples of external search integration