Skip to content

This is a project demonstrating possible customisations for the library Umbraco.Cms.Integrations.Search.Algolia.

License

Notifications You must be signed in to change notification settings

geann/demo-umbraco-algolia-integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

This is a project demonstrating possible customisations for the library Umbraco.Cms.Integrations.Search.Algolia.

The project is currently based on

  • Umbraco 13.3.2
  • Umbraco.Cms.Integrations.Search.Algolia 2.1.5

Customisations

1. Property converters

Converters are the best way to extend the library if you need to customise how specific properties are stored in Algolia indexes.

This class shows an example of property converter for the Umbraco.DateTime property editor. As Algolia works with dates in the Unix timestamp format, the method converts Umbraco properties to this format.

📖 Additional information:

2. Record builders

Record builders usually require two classes: a custom record class inherited from Record and a record builder class implementing the interface IRecordBuilder.

This is an example showing how to add a custom attribute to the record object and populate it from a standard field of IContent object. In this case, ParentPageId is defined as a separate attribute so that it can be used for filtering articles by parent page ID if they are stored in different areas of the content tree but based on the same Article document type.

This record builder is required for document types that should support geographical search, for example office locations or offline shops. Algolia requires that geolocation data is stored in a special attribute called _geoloc. This attribute should be an object or an array of objects with two attributes: lat and lng. The GeoRecord class is a custom record with one geographical location, and the class LocationRecordBuilder shows how this record can be populated (assuming that latitude and longitude are stored as a comma-separated string in a property called coordinates. This is just an example and the format and name of the property can easily be changed.

📖 Additional information:

3. Notification handler

The out-of-the-box AlgoliaContentCacheRefresherHandler is not built for inheritance, as none of its methods are virtual. It is still possible to create a custom class implementing INotificationAsyncHandler and define your own logic for retrieving updated entities and processing them, though be careful with this customisation and don't use it unless you absolutely have to because future library upgrades may become more difficult.

This notification handler is copied from the standard one that comes with the library, the only change is in the RebuildIndex() method. It checks if the toggle property hideFromSearch is set for the current entity and if yes, it skips or deletes the entity from the index. This may be required in scenarios when some non-searchable pages should only be accessed via a direct link but not visible in search results or on listing pages.

The class DemoUmbracoAlgoliaIntegrationComposer uses an extension method to remove the standard implementation of AlgoliaContentCacheRefresherHandler from the DI container. Please note that is code is commented out intentionally so that people who want to use it have to enable it implicitly.

About

This is a project demonstrating possible customisations for the library Umbraco.Cms.Integrations.Search.Algolia.

Resources

License

Stars

Watchers

Forks