Tagged: Dynamic Tag Enhancement

Sitecore : Dynamic Tag Enhancement for Algolia Search Provider

Sitecore-Blog-Hero-Image-3.png

While integrating Sitecore with Algolia Search Provider, I encountered a scenario where I needed to add many fields dynamically. The field name and value are both dynamic based on the content page.

Initially, I thought of it as a computed field, but then the field name is dynamic, and I was wondering how to add dynamic fields to the Index records.

The TagProcessor comes to the rescue – The existing Tag Processor ensures that tags are dynamically added, structured, and optimized before indexing, which outputs _tags in the indexing record.

Algolia Record Search:

 

Sitecore-Algolia-Serach-Provider-Tag-Processor-Computed-Fields-1.png

 

The config for the existing tag processor looks like this –

AlgoliaConfiguration.sc1021.config:

 

 

CategoryDataProcessor:

  • Since we needed to incorporate dynamic tags into our project, I began exploring the functionality of AlgoliaTagsProcessor. Creating another Tag processor, for example, CategoryDataProcessor –allowed us to generate dynamic tags efficiently.
  •  The ProcessDocument method ensures that the Sitecore items being processed match the expected Category Listing Template.
  • After Processing, the extracted data is added dynamically to the JObject doc to the Alglolia Index record.

 

 

  • However, this overwrites the existing_tags in Algolia index. I’m looking for a way to make both work together while also allowing the flexibility to add more dynamic tags in the future if needed.
  • Adding a wrapper class – AlgoliaCustomTagProcessor, which should loop through each Processor and call the ProcessDocument method.
  • This will ensure that each TagProcessor is called and doesn’t overwrite the existing _tags.

AlgoliaCustomTagProcessor:

 

AlgoliaDocumentBuilder:

Modify the AlgoliaDocumentBuilder to process both tag documents – 

  • Initialize the new CustomTagProcessor in the Constructor.
  • Add the GenerateCustomTags() method, which should call ProcessDocuments in the CustomTagProcessor class.

The following is the modified AlgoliaDocumentBuilder code – 

 

AlgoliaConfiguration.sc1021.config:

  • Let’s add the new CustomTagProcessor to the config file.
  • Now, we have two tag processors nested into each other and wrapped into our CustomTagProcessor class.
  • It can be extended to any dynamic Tags we want in the future.

 

The final dynamic category tags were added to the Algloia record, yay! 

It worked!

 

Sitecore-Algolia-Serach-Provider-Tag-Processor-Computed-Fields-2.png

Hope this helps.

Happy Sitecoring!

0