Try our conversational search powered by Generative AI!

Loading...
Area: Optimizely Search & Navigation
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

Introduction

In some situations, especially when working with classes from third party libraries, it can be very useful to index values that are not exposed as properties on the objects. By customizing the Client conventions, we can include just about any value that will be indexed by including delegates whose return value will be included when indexing. These delegates can use methods, extension methods and operations on the properties exposed by the indexed object.

Examples

For instance, given that we have a BlogPost class with a list of tags we can include the tag count by configuring the Client conventions to include an expression that retrieves it.

C#
//using EPiServer.Find.ClientConventions;

client.Conventions.ForInstancesOf<BlogPost>()
    .IncludeField(x => x.Tags.Count());

We are then able to search and filter for the indexed value:

C#
client.Search<BlogPost>()
    .Filter(x => x.Tags.Count().Match(firstIndexedObject.Tags.Count()))
    .GetResult();

It is also possible to supply a delegate that will be used to set the value when returned in a search result.

C#
client.Conventions.ForInstancesOf<BlogPost>()
    .IncludeField(
        x => x.GetSomeField(), 
        (x, value) => x.SetSomeField(value));
Do you find this information helpful? Please log in to provide feedback.

Last updated: Jun 10, 2014

Recommended reading