Multiple Index lookups

16 views
Skip to first unread message

Thomas Efer

unread,
Aug 23, 2013, 6:08:10 AM8/23/13
to pacer...@googlegroups.com
Hi Darrick (and other pacer experts),

my question is quite related to Steven's Thread on "multiple roots for query":


I want to be able to have an array of values like ["Alice","Bob"] and get all the nodes where an (indexed) property (like :name) has one of these values.

For a single value it is just g.v(:name=>"Alice"). A "V-Index" Pipe-Thingy is assembled and everything is working smoothly.

My naive syntax guess on g.v(:name=>["Alice","Bob"]) does (understandably) not work and reports:

"Value [[Ljava.lang.Object;@1234567ab] is not an instance of the expected data type for property key [name]. Expected: class java.lang.String, found: class [Ljava.lang.Object;"

Finally another approach

g.v([{:name=>"Alice"},{:name=>"Bob"}])

throws no error but does something completely different (and in this case useless, by the way...): V-Index(name: "Alice") -> V-Property(name=="Bob")

As far as I dug into Pipes I do not see any possibility to have nodes selected from an index by more than one target value. Is that true?


Well, one workaround to get all the matched nodes from the index into one route could be something like this:

["Alice","Bob"].map{|n| g.v({:name=>n}).element_ids.to_a}.flatten.id_to_element_route(based_on: g.v)

But this roundtrip over map and the ids feels kind of wrong. And the debug info for the new route "Obj 2 ids -> lookup -> is_not(nil)" is also not as useful anymore.

Is there any better way to achieve what I want? Have I overlooked something?


Thanks alot for your support!

Darrick Wiebe

unread,
Aug 23, 2013, 11:37:45 AM8/23/13
to Pacer Group
Hey Thomas,

 If you are using Neo4j, you can use this syntax to accomplish it:

g.v(name: Set["Alice", "Bob"])

range queries also exist in Neo4j as follows:

g.v(number: (1...10))
g.v(string: ("A".."Z"))

I haven't implemented similar support for other graphdbs yet, but if you look at the implementation in pacer-neo4j, you may get a hint how to do it for them, too. It'd be great to standardize on that feature as I've found it super useful!

Cheers,
Darrick

PS. for more complex index lookups in Neo4j, you can also just explicitly hit the index: g.lucene("some lucene query")


--
You received this message because you are subscribed to the Google Groups "pacer-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pacer-users...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Thomas Efer

unread,
Aug 23, 2013, 4:43:21 PM8/23/13
to pacer...@googlegroups.com
Hi Darrick,

thanks for the quick response! I am working with Titan and therefore can't use the fancy pacer-neo4j functions. The Set[]-notation works in principle put degrades to an unindexed "V-Property(author_name IN ("Alice", "Bob"))".

Most parts of pacer still look to me like dark magic but I begin to see some light. I now ended up implementing the functionality I needed in a separate method of the graph class - which tuned out to be super easy.

For the record here is what works for me:

def v_lookup(property,values)
  values.
    map{|v| blueprints_graph.get_vertices(property.to_s,v.to_java).
    reject{|v|v==nil}.to_a}.to_a.flatten.
    to_route(:graph=>self,:based_on=>v,:unwrap=>true,:route_name=>"V-IndexMulti")
end

g.v_lookup(:name, ["Alice","Bob"]) gives the correct nodes (using the index and so not scanning over all vertices)!

Again thanks for the hints and best regards


Thomas
Reply all
Reply to author
Forward
0 new messages