orientechnologies / orientdb-gremlin

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

Get vertex by class #49

Open Krever opened 8 years ago

Krever commented 8 years ago

Hi, is it possible to make a query that gives back all vertices of specified class?

There is a graph.getVerticesOfClass("xxx") method availible in current orientd graph api but not in this backend. Also I have found following snippets:

graph.V.has("@class","xxx")
graph.V.hasLabel("class:xxx")

but they're not working either.

Thanks for help :)

Edit: Now i see, that I can use hasLabel stripping first two characters of my class, because of prefixes used by you(V, E). Is there any way of configuration, so I can disable these prefixes?

Moreover such call rise a warning

WARNING: scanning through all vertices without using an index for Traversal [OrientGraphStep(vertex,[~label.eq(x)])]

graph.getVerticesOfClass("xxx") doesn't have such problem. Should I add some index manually?

mpollmeier commented 8 years ago

Sorry for the late reply, I'm only just back from holidays.

You can configure this behaviour (prefixing V and E) on OrientGraphFactory.setLabelAsClassName(boolean)

Are you using an existing orientdb that was not created with this driver?

Krever commented 8 years ago

No problem, I hope you've had happy holidays.

Yes, I'm using existing DB. I prefer to create a schema by script rather than by code.

Thanks for your help :)

wildroco commented 8 years ago

Hi,

Why I have to query like this to get vertices by class? graph.V.has("@class","xxx") graph.V.hasLabel("class:xxx")

not like this? (by greamlin-scala syntax) graph.V.has("xxx")

Is this difference come from nature of orientDB..?

...anyway, thx to your contributions very much!

mpollmeier commented 8 years ago

has(String) always checks for property values, not class names, this is true for all gremlin variants and databases. not sure if I understood you correctly...?

wildroco commented 8 years ago

Oh, sorry.

I mean: hasLabel(string)

And I found it works fine after some test.

Anyway, I queried my class "A" using g. V. hasLabel("A")

and it seems works below too. g. V. hasLabel("class:A")

Is there any difference or better way between them?