London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

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

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));

Last updated: Sep 26, 2013