Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

Dev guideRecipesAPI ReferenceChangelog
Dev guideRecipesUser GuidesNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Natural language processing

How to use natural language processing to enhance search accuracy and deliver relevant, semantically meaningful results.

Optimizely Graph enhances search accuracy using language-specific natural language processing (NLP). This lets you retrieve more relevant and semantically meaningful results based on your language preferences and search intent.

Language-specific search

Use this query to perform a full-text search in a specific language. Optimizely Graph applies language-aware tokenization, stemming, and ranking to return the most relevant results.

The following query searches for the phrase “machine learning algorithms” in English and ranks results using semantic relevance:

query LanguageSpecificSearch(
  $searchTerm: String!
  $locale: [Locales!]!
) {
  Content(
    where: {
      _fulltext: { match: $searchTerm }
    }
    locale: $locale
    orderBy: { _ranking: SEMANTIC }
  ) {
    items {
      Name
      _score
      Language {
        Name
        DisplayName
      }
      _concreteType
      ... on ArticlePage {
        TeaserText
        StartPublish
      }
      ... on ProductPage {
        TeaserText
      }
    }
  }
}

The following are some example variables:

{
  "searchTerm": "machine learning algorithms",
  "locale": ["en"]
}

Semantic search with language context

Use this query to combine semantic search with language-specific context and content type filtering. It supports synonym expansion and boosts relevance for better precision.

The following query:

  • Searches for a term using semantic understanding.
  • Applies synonym matching.
  • Filters by content type.
  • Returns language and type facets for further refinement.
query SemanticLanguageSearch(
  $searchTerm: String!
  $locale: [Locales!]!
  $contentTypes: [String!]
) {
  Content(
    locale: $locale
    where: {
      _and: [
        { _fulltext: { 
            match: $searchTerm
            synonyms: ONE
            boost: 8
          }
        }
      ]
    }
    orderBy: { _ranking: SEMANTIC }
    limit: 15
  ) {
    facets {
      Language {
        Name {
          name
          count
        }
      }
      _concreteType(filters:$contentTypes) {
        name
        count
      }
    }
    items {
      Name
      _score
      Language {
        Name
        DisplayName
      }
      _concreteType
      ... on ArticlePage {
        TeaserText
        Category {
          Name
        }
      }
    }
  }
}

Conclusion

Optimizely Graph’s natural language processing capabilities enable you to deliver smarter, language-aware search experiences. Whether you are targeting a specific locale or leveraging semantic context, these queries help ensure you find the most relevant content in your preferred language.