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.
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.
//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:
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.
client.Conventions.ForInstancesOf<BlogPost>() .IncludeField( x => x.GetSomeField(), (x, value) => x.SetSomeField(value));
Last updated: Jun 10, 2014