This content is retired. See latest version here.

Last updated: Nov 16 2015

In some situations, especially when you work with classes from third-party libraries, you can index values that are not exposed as properties on the objects. This topic explains how to customize Client conventions to include fields to be indexed in Episerver Find.

How it works

By customizing the Client conventions, you can include just about any value that will be indexed by including delegates whose return value is included when indexing. These delegates can use methods, extension methods, and operations on the properties exposed by the indexed object.

Examples

Given a BlogPost class with a list of tags, you 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());

You can then search and filter for the indexed value:

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

You also can supply a delegate that is 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));

Comments