HomeDev GuideRecipesAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Search content in Optimizely Graph using C# SDK

Run full-text searches in Optimizely Graph, filter results, boost relevance, and track user clicks.

Use .SearchFor() to run full-text searches against indexed content in Optimizely Graph. Search all text fields or target specific fields, boost relevance, apply filters, and track which results users click.

Combine .SearchFor() with .UsingFullText() to search all text fields, or with .UsingField() to target specific fields and control relevance boosting.

Search across all fields

.UsingFullText() searches every indexed text field:

var result = await client
    .QueryContent<BlogPostPage>()
    .SearchFor("graph api")
    .UsingFullText()
    .GetAsContentAsync();

Search a specific field

.UsingField() limits the search to one field:

var result = await client
    .QueryContent<BlogPostPage>()
    .SearchFor("sorting")
    .UsingField(x => x.Title!)
    .GetAsContentAsync();

Boost relevance for specific fields

Pass a boost value to increase the importance of matches in specific fields. Higher numbers have greater influence:

var result = await client
    .QueryContent<BlogPostPage>()
    .SearchFor("api")
    .UsingField(x => x.Title!, boost: 3)
    .UsingField(x => x.Tags!, boost: 1)
    .GetAsContentAsync();
📘

Note

Matches in Title rank three times higher than matches in Tags.

Combine search with filters

Chain .Where() to narrow search results by field values:

var result = await client
    .QueryContent<BlogPostPage>()
    .SearchFor("api")
    .UsingFullText()
    .Where(x => x.BlogCategory == "Tutorials")
    .GetAsContentAsync();

Enable click-through tracking

Add .Track() to your search query to record which results users click.

var result = await client
    .QueryContent<BlogPostPage>()
    .SearchFor("api")
    .UsingFullText()
    .Track()
    .GetAsContentAsync();
📘

Note

.Track() works only when combined with .SearchFor(). See Track search result clicks in C# SDK for the full setup.