Back

BLOG • DIGITAL INSIGHTS

Index RelatedData and RelatedMedia in Sitefinity

Indexing related data fields in Sitefinity one by one requires ongoing code changes. This post shows a more generic approach using a custom inbound pipe and a Regex naming convention, letting editors add new related fields to the search index from the backend without touching the code.

Sitefinity CMS

Recently I was working on a few projects with Sitefinity CMS where we needed to index a related data field. This can be achieved fairly easily with a custom inbound pipe. But then the client asked us to index more related data fields. Rather than adding code for every related data field individually, I decided to write something more generic - allowing the client to add related data fields from the backend using additional fields of the search index.

Since Sitefinity does not allow dots, slashes, underscores or other special characters in field names, I needed a different approach. The easiest solution was to use a simple naming convention and use Regex to split the name and map it to the real fields.

The Custom Inbound Pipe

How the Regex Works

The most important part is this line:

private Regex relatedDataRegex = new Regex(@"(?<=RelatedData)(\w+)(?>Field)(\w+)", RegexOptions.Compiled);

This Regex maps the additional field name to the real related data field. It expects the following format: RelatedData{FieldName}Field{RelatedFieldProperty}.

For example, RelatedDataCountryFieldTitle will index the Title of the related Country field.

One limitation of this approach is that nested related fields are not supported - however the code could be easily extended to handle them.

Register in Global.asax.cs

Finally, register the pipe for all dynamic content modules (or only the ones you need) on the Bootstrapper_Initialized event in Global.asax.cs:

Read More

Explore more insights and case studies from our team.