Episerver Find: Include Matches in Fields Belonging to Derived Child Classes
When doing a Free Text Search in Episerver Find, you find yourself relying on an instance of ITypeSearch to build your query through method chaining. Since ITypeSearch<> is generic, it is intended to describe what kind of content your Free Text Search is meant to locate – e.g. PageData, ProductContent or simply IContent.
If we speak to derived classes of ProductContent, containing additional meta data extending the understanding of a generic product, these do not become searchable through InField unless you apply .InAllField(). Imagine above example, where my Episerver solution contains a child class, of ProductContent, named EatableProductContent, which is intended to be the product type of all my products that are eatable, hence requires nutritional information. By default, the Episerver Find InField code API does not enable me to specify NutritionalInformation through the fieldSelector argument, because it does not belong to ProductContent.
Question is now, how do we include NutritionalInformation as a search field, if the type considered is EatableProductContent.
We can easily extend the Episerver Find code API to enable a generic implementation of InField, enabling us to specify the derived child class in which to apply the fieldSelector argument too.
After that code has been applied to your solution, you can simply leverage one of the new extension methods.
We find this method of applying content type dependent fieldSelector arguments very helpful, especially when dealing with a complicated product data model in our Episerver and PIM solutions.