orientechnologies / orientdb-gremlin

TinkerPop3 Graph Structure Implementation for OrientDB
Apache License 2.0
91 stars 32 forks source link

Indexing Across Multiple Labels #96

Closed fppt closed 7 years ago

fppt commented 7 years ago

Hi Guys,

I have noticed that in order to create an index you have to do the following:

BaseConfiguration indexConfig = new BaseConfiguration();
indexConfig.setProperty(KEY_TYPE, otype);
indexConfig.setProperty(UNIQUE, "UNIQUE");
graph.createVertexIndex("property", "label1", indexConfig);
graph.createVertexIndex("property", "label2", indexConfig);

This would make the following traversal faster:

graph.traversal().V().hasLabel("label1").has("property", "a thing");

I have the problem that sometimes I don't know my exact label. Ideally I would like to do the following:

graph.traversal().V().hasLabel("label1", "label2").has("property", "a thing");

However, when I do that I see the indices are no longer used. Is there anyway to use the index across multiple labels ? Or can I index something without specifying the label ?

Thanks once again for your help.

mpollmeier commented 7 years ago

This would be totally possible, but we'd need to pimp the index lookup a bit. At the moment it's very simplistic: have a look at https://github.com/mpollmeier/orientdb-gremlin/blob/master/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/traversal/step/sideEffect/OrientGraphStep.java#L121

It simply looks for the hasLabel step, get's the orient class and looks up the first index for the given property. Would you like to experiment a bit and send us a PR?

fppt commented 7 years ago

Thanks for the reply Michael. I will have a go at implementing this and will submit a PR if I have any luck.

fppt commented 7 years ago

Took a very naive attempt at implementing this: https://github.com/mpollmeier/orientdb-gremlin/pull/97