Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In "Phase 2" functionality, how to find/get nodes? #76

Closed
mjones-rpx opened this issue Jan 22, 2013 · 14 comments
Closed

In "Phase 2" functionality, how to find/get nodes? #76

mjones-rpx opened this issue Jan 22, 2013 · 14 comments

Comments

@mjones-rpx
Copy link

Hi -- this may not be implemented yet, but I wanted to check. When using the "Phase 2" style that mimics neo4j.rb, is there a way to find/get using an index? Without that, I'm trying to determine how to do this:

someone = @neo.get_node_index("people", "name", "Bob")[0]
=> Hash containing the node info
someone_node = Neography::Node.load(id)

Obviously this isn't ideal since it's two calls, but also, the Hash returned from the get_node_index() call doesn't actually have the ID in an easy-to-get place -- it seems like I'd have to take "self" and parse out the ID from the end of the URL. Not great.

Is there something in the "Phase 2" functionality that I haven't stumbled on yet? Just curious where this stands. Thanks for the great work on neography!

@maxdemarzi
Copy link
Owner

Sorry didn't mean to close it.

https://github.com/maxdemarzi/neography/wiki/Phase-2-Nodes <-- additional information.

Neography::Node.find(index, key, value)                              # advanced query of the node index with the given key/value pair
Neography::Node.find(index, query)                                   # advanced query of the node index with the given query

@maxdemarzi
Copy link
Owner

So now you can do:
someone = Neography::Node.find("people", "name", "Bob")

It returns a single node if only one is found otherwise it returns an array.
Same for relationships.

@mjones-rpx
Copy link
Author

Thanks for looking into it so quickly! For some reason it's unable to find neo_server? See below:

$ irb
> require 'neography'
 => true
> mynode = Neography::Node.load(4)
 =>  #<Neography::Node name="Node1", type="mytype">
> mynode = Neography::Node.find('companies','name','Node1')
NameError: undefined local variable or method `neo_server' for Neography::Node:Class
        from /Users/mason/.rvm/gems/ruby-1.9.3-p194@neo4j-example/gems/neography-1.0.5/lib/neography/index.rb:28:in `find'
        from (irb):4
        from /Users/mason/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'

@maxdemarzi
Copy link
Owner

Change your gemfile to:

gem "neography", :git => "git://github.com/maxdemarzi/neography.git"

I think I'm missing some unit tests, but once those are done I'll push a new version.

@mjones-rpx
Copy link
Author

Hmm, still getting the same results. Bundle install shows "Using neography (1.0.5) from git://github.com/maxdemarzi/neography.git (at master)". Still gives me:

NameError: undefined local variable or method `neo_server' for Neography::Node:Class
        from /Users/mason/.rvm/gems/ruby-1.9.3-p194@neo4j-example/gems/neography-1.0.5/lib/neography/index.rb:28:in `find'
        from (irb):2
        from /Users/mason/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'

@maxdemarzi
Copy link
Owner

Ok... I just released a 1.0.6 version... still missing tests, but go ahead and give that a shot.

@mjones-rpx
Copy link
Author

Looks good, thanks very much. That previous issue with 1.0.5 may in fact have been user error (damned 'bundle exec') as well, but in any case it's working now!

@pboling
Copy link
Contributor

pboling commented Jan 30, 2013

@maxdemarzi I am trying to figure out how to use Phase 2 as well. Looking at the source I see nodes are created with this:

db.create_node(props)

How does one create nodes with an index? I am trying to figure out how to store my nodes so I can query them based on properties, and if I don't create them with an index, it seems like they become nearly impossible to access.

I am building something very similar to your neosocial example. Is Phase 2 capable of doing something like that use case?

@maxdemarzi
Copy link
Owner

You are right, that's stuff not documented.

node1 = Neography::Node.create("age" => 31, "name" => "Max")
node1.add_to_index("people", "name", node1.name) <= ugly

node1.add_to_index("people", :name) <= would this be better?

@pboling
Copy link
Contributor

pboling commented Jan 30, 2013

@maxdemarzi Thanks for the quick response!

I am a complete neo4j noob, still trying to grok the whole concept, and simultaneously build an app on it. So if the goal is to make it simple for Noob (a good goal I think) and clear, then yes I think the second format is best.

node1.add_to_index("people", :name)

If the key on the index is not the same as the key on the node, or if the value is arbitrary, then you might make the second parameter optional.

node1 = Neography::Node.create("age" => 31, "first_name" => "Max", :last_name => "de Marzi") 
node1.add_to_index("people", "name", "#{node1.first_name} #{node1.last_name}")

Would that even work? Can the value be arbitrary, or does it have to match an actual property value on the node?

@chintanparikh
Copy link

How would I use Neography::Node.find(index, key, value) with multiple key value pairs?

@maxdemarzi
Copy link
Owner

Neography::Node.find(index, query)
Neography::Node.find("Users", "gender: male AND age: 21")

@Papipo
Copy link

Papipo commented May 20, 2013

Is it possible to create a node and add it to an index in a single query so it's an atomic operation?

@maxdemarzi
Copy link
Owner

Look at cypher label functionality for that. We're moving away from complex phase 2 functionality and instead headed down the cypher path. See the cypher gem for possibilities.

willkessler pushed a commit to willkessler/neography that referenced this issue Apr 21, 2014
move typecasting closer to read/save to graph
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants