Tagged: Algolia Search Provider

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

Algolia Search Provider for Sitecore 10.2.1

Algolia Search Provider for Sitecore 10.2.1

The Algolia Search Provider for Sitecore is a powerful integration combining robust content management capabilities with Algolia’s lightning-fast, full-text search engine.

This provider enables Sitecore-driven websites and applications to deliver instant, relevant, and highly customizable search experiences to end-users, ensuring faster content discovery and improved user engagement.

While exploring, I found that Dmitry Harnitski and Peter Procházka have implemented the Algolia Search Provider for Sitecore 9.1 and previous versions. Thank you so much!

https://github.com/dharnitski/Sitecore.Algolia

https://github.com/chorpo/Sitecore.Algolia/tree/sitecore91

Upgrading to Sitecore 10.2.1

The following are the steps taken for upgrading Sitecore 10.2.1 – 

  •  I forked from Peter Procházka’s Sitecore 9.1 branch

https://github.com/chorpo/Sitecore.Algolia/tree/sitecore91

  • Upgraded the Sitecore NuGet packages to 10.2.1.

Sitecore-Algolia-Search-Provider-10-2-1-Upgrade-1.png

  • Algolia.Search NuGet package upgraded 6.12.1

Sitecore-Algolia-Search-Provider-10-2-1-Upgrade-4.png

Sitecore-Algolia-Search-Provider-10-2-1-Upgrade-2.png

  • Finally, able to build the solution successfully. 

Sitecore-Algolia-Search-Provider-10-2-1-Upgrade-3.png

  • After the build was successful, I shifted the module to the existing solution.
  • I didn’t get a chance to upgrade the unit test project. If you have upgraded, please let me know.

The module is checked into the following repository.

https://github.com/Madhumidha/Sitecore.Algolia/tree/Sitecore1021

The repo has all the instructions on how to set up and configuration details.

Hope this helps.

Happy Sitecoring!

 

0