Content types
How to create content types using the Optimizely Graph .NET Source SDK.
NoteOptimizely Graph .NET Source SDK is optimized for CMS 12. Learn more about the C# SDK for CMS 13.
Content types define the structure of content you manage and query in Optimizely Graph. They let you specify content attributes and determine how they should be indexed or queried for flexible content management and retrieval to meet specific business needs.
Index types
The following code example uses index types to optimize how the SDK indexes data fields within a content type for search and query.
public class Cafe
{
public string Name { get; set; }
public DateTime Established { get; set; }
public Location Address { get; set; }
public Menu Menu { get; set; }
}
public class Location
{
public string City { get; set; }
public string State { get; set; }
public string Zipcode { get; set; }
public string Country { get; set; }
}
public class Menu
{
public Beverage Beverage { get; set; }
public Food Food { get; set; }
}
public class Beverage
{
public string Name { get; set; }
public double Price { get; set; }
public List<string> Sizes { get; set; }
}
public class Food
{
public string Name { get; set; }
public double Price { get; set; }
public bool IsAvailable { get; set; }
}These indexing options help you configure your content for faster retrievals and more precise queries.
PropertyType– Indexes nested data objects within your content structure.Queryable– Supports filtering, ordering, and faceting by specific fields, including thecontainsoperator. See Operators.Searchable– Supports full-text and semantic search on vectorized fields, including thematchoperator, ordering, and faceting.
Configure content types
Map and configure your content for efficient indexing using the following code sample:
client.ConfigureContentType<Cafe>()
.Field(x => x.Name, IndexingType.Queryable)
.Field(x => x.Established, IndexingType.Searchable)
.Field(x => x.Address, IndexingType.PropertyType)
.Field(x => x.Menu, IndexingType.PropertyType);
client.ConfigurePropertyType<Location>()
.Field(x => x.City, IndexingType.Queryable)
.Field(x => x.State, IndexingType.Queryable)
.Field(x => x.Zipcode, IndexingType.Searchable)
.Field(x => x.Country, IndexingType.Searchable);
client.ConfigurePropertyType<Menu>()
.Field(x => x.Beverage, IndexingType.PropertyType)
.Field(x => x.Food, IndexingType.PropertyType);
client.ConfigurePropertyType<Beverage>()
.Field(x => x.Name, IndexingType.Queryable)
.Field(x => x.Price, IndexingType.Queryable)
.Field(x => x.Sizes, IndexingType.Searchable);
client.ConfigurePropertyType<Food>()
.Field(x => x.Name, IndexingType.Queryable)
.Field(x => x.Price, IndexingType.Queryable)
.Field(x => x.IsAvailable, IndexingType.Searchable);Set language
Before saving your content types, set your preferred language using client.AddLanguage, as shown in the following code sample:
client.AddLanguage("en");Save content types
With the initialized client, save your content types. The SDK manages the backend request construction and interacts with Optimizely Graph on your behalf.
await client.SaveTypesAsync();View types
After completing the previous steps, go to the interactive GraphiQL page to view and query your configured types. See Access the interactive GraphiQL page for instructions.
NoteRemember to add your
singlekeyto the query parameter to access the GraphiQL page.
Next steps
After configuring your content types, sync your data with Optimizely Graph for content management and retrieval. See Sync content for information on syncing content, creating unique identifiers, and pushing data.
Updated 2 days ago
