Delete old records

I am trying to integrate Algolia with an older version of Opencart ecommerce system. Currently I am able to export products as JSON object (name, image, description, category, manufacturer) and successfully import to Algolia. Searching also works.

One thing I don’t know how I am going to resolve: delete old records. Isn’t there a function in Algolia which automatically deletes records, which are not in import file?

I tried $index->clearObjects(), but it’s a very expensive oepration at 10 000 objects, the units are not going to last long.

Don’t beat me, I am not a real programmer, just a hobbyist. :slightly_smiling_face:

Hey,

I understand you are trying to get rid of outdated records but would like to limit the number of operations required.

Algolia allows you to delete records one by one. So in your case, I think the optimal way would be to hook into the opencart system and try to detect when a product gets deleted. When that happens, you should fire a deleteObject request on your Algolia index.

This way you would only remove the records that are indeed no longer required without needing to fully re-index everything.

I hope this makes sense, let me know.

Not bad idea at all, I’ll try it later. One more thing is in my mind (it would be good to use the two together), but I don’t know if it is possible. Before exporting to Algolia: query all objectID’s from Algolia and compare with the objectID’s we trying to export. Save to an array which are not in the local data and send a request to delete these items.

Can we somehow query all objectID’s from Algolia?

Actually in meantime I did this. I am exporting all objects from Algolia:

$objects = [];
foreach ($index->browseObjects() as $hit) {
 $objects[] = $hit;
}
file_put_contents('/var/www/algolia.export', json_encode($objects));

And I am comparing with local objects from OpenCart. Objects which are not in export file from Algolia:

$index->deleteObjects($deleteArray);

Simple is that.

One more question:

Exporting objects like this foreach ($index->browseObjects() as $hit) { from Algolia is how expensive at 10 000 items? It is counted as 10 000 search = 1 unit?