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

Search content in Optimizely Graph with the 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. Use .UsingField() to target specific fields and control relevance boosting.

Search across all fields

Search every indexed text field when the match could appear anywhere in the content.

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

Search a specific field

Restrict the search to a single field for more targeted results.

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.