Assign product to subcategory, without assigning it to parent category

Say that I have the following category structure:

  • Root
    • Men
    • Women
      • Tops

And a product “T-Shirt”, which is assigned only in “Tops” category in Magento.

When I run reindex in Magento, the product is assigned to both Women and Women>Tops categories in Algolia, which is NOT what I want.

I was looking at vendor/algolia/algoliasearch-magento-2/Helper/Entity/ProductHelper.php (addCategoryData() method, this is where the whole logic is placed), and I couldn’t make it work.

So my question is, would it be possible to assign a product to subcategory, without assigning it to parent category?

We treat these category structures as hierarchies, so the assumption is that if a product belongs to a subcategory, that product would also be part of all categories above it.