Full Text Index on Nodes with specific labels

Hi,
I want to create a full-text index for nodes that contains specific labels
For example index for nodes with labels: FOOD and FRUITS

I tried something like:
CALL db.index.fulltext.createNodeIndex("foodIndex", ['FOOD', 'FRUITS'], ['content']);
but it creates index on nodes which have FOOD or FRUIT label.

Is it possible to create an index only on nodes that have both labels set?

Regards,
Jacob

Create a (temporary) FOODFRUITS Label such that both labels are present. Then fulltext index using the Label FOODFRUITS. You can delete the FOODFRUITS label later or keep it as it may be useful.

Ok but what if i will add another node with FOOD and FRUIT label?

I’d like to have solution where I can group specific labels, not creating new one for every single combination.

There may be VEGETABLE or others groups of food products.

In my project I also have more factors for example unit type label

Good point.

I'm guessing you could have a Trigger that checks whenever a FOOD and/or FRUIT label gets added to an existing Node and/or when the Node gets created with the Label and then automatically creates the Union of the two.

I tried seeing if I could find the source on GitHub for db.index.fulltext.createNodeIndex, which is where this would need to be tweaked but I'm not sure where to find it...

Ok I will try it. What about scalability performance. It won’t affect it if my database will grow much? It’s more theoretical question.

What if I will change label from FRUIT to VEGETABLE? Should I create trigger which will automatically change the “combined” label.

Also there is another thing. I want to have indexes which different depth levels. For example I want to have index for FOOD, for FOOD DIARY and for FOOD DIARY MILLILITERS. So every node should have 3 additional “combined” labels based on single ones, right?

I’m here focused on read speed and don’t care much about write speed.

Overall it would be nice to have indexes based on on nodes with both labels.
I think createNodeIndex doesn’t allow it alone.

I agree that your use case is a reasonable one (although uncommon.)

It needs to be made as a request to the APOC powers.

Or if you or somebody you know is clever enough, to make an addition to the db.index.fulltext to have a version of the function that requires all the Labels in the list instead of any Label. Then make a Pull Request to have it added.

I'm stumped as to where the source code is, otherwise I might take a crack at it myself (just for the experience.)

@clem I probably found the source code of it

I’m really not into Java so if you would like to write it for experience that would be amazing :star_struck: