Indexing a custom Magento 2 table (data)

I’m needing to add content from a custom table created by a Magento 2 module to an Algolia index and then have that content searchable through the autocomplete display and on the site search page (I’ve enabled Algolia’s instant search page to replace the default Magento search results page).

I’ve looked at a couple of resources but they don’t seem to discuss what I’m trying to accomplish.

Hello @greg2,

there are 2 options to have this achieved.

1) Additional section

If the custom data type is attribute of a product (for example: color, brand, size, …), then it can be indexed out of the box with Additional sections feature.

To enabled it, navigate to Algolia configuration (Instant search page) in Magento and add this attribute to Attributes for faceting table. Then go to Autocomplete section and add this attribute to Additional sections table (the attribute cannot be added there before you add it to facets).

Then save the configuration and reindex Algolia’s Additional sections indexer.

2) Custom indexer

If the data is not related to products, then you’ll need to write a completely new indexer. You can create your own custom extension and create new indexer fetching this data and pushing it to Algolia. You can take inspiration from CMS pages indexer.

When you have the data indexed, you can integrate it to Autocomplete menu. You can learn how to do it in Adding autocomplete source tutorial.

Thanks again @jan.petr. It looks like I’ll need to go with the second option you outlined.

1 Like