-
Notifications
You must be signed in to change notification settings - Fork 12
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
Using with Neo4j 3.x #17
Comments
Unfortunately this repo does not work with new procedures. Here's it: First of all, install neo4j_spatial like this: gem 'neo4jrb_spatial', github: 'neo4jrb/neo4jrb_spatial', branch: 'neo4j-8.x' Create a module Neo4j3Spatial
extend ActiveSupport::Concern
module ClassMethods
def create_index!(type: 'SimplePoint')
return if layer?(spatial_index_name)
_query.call('spatial.addLayer({name}, {type}, "lon:lat")')
.params(name: spatial_index_name, type: type).to_a
end
def layer?(name)
_query.call('spatial.layers() YIELD name, signature')
.with(:name).where(name: name).return(:name).any?
end
private
def _query
Neo4j::ActiveBase.new_query
end
end
included do
scope :within_distance, lambda { |options|
Neo4j::ActiveBase
.new_query
.call('spatial.withinDistance({layer}, {coordinate}, {distance}) YIELD node, distance')
.params(layer: spatial_index_name,
coordinate: { lon: options[:lon], lat: options[:lat] },
distance: options[:distance])
.with(:node).where("(node:#{mapped_label_name})")
.pluck(:node)
}
scope :bbox, lambda { |box|
Neo4j::ActiveBase
.new_query
.call('spatial.bbox({layer}, {x1}, {x2}) YIELD node')
.params(layer: spatial_index_name, x1: { lon: box[0], lat: box[1] }, x2: { lon: box[2], lat: box[3] })
.with(:node).pluck(:node)
}
create_index!
end
delegate :layer?, to: :class
def add_to_spatial_index
return if !lat? || !lon? || !layer?(self.class.spatial_index_name)
Neo4j::ActiveBase
.new_query
.match_nodes(n: neo_id)
.with(:n).call('spatial.addNode({layer}, n) YIELD node')
.params(layer: self.class.spatial_index_name).pluck(:n)
end
end Here's a sample usage: class YourModel
include Neo4j::ActiveNode
include Neo4j::ActiveNode::Spatial
spatial_index 'your_index'
include Neo4j3Spatial
end
YourModel.within_distance(...)
ecc... |
@ProGM hi, really appreciate your answer. I'm testing this out but getting |
I can't really test right now, but the index creation should be provided when including the module. (check the last line of the "included" block) You can manually trigger it by using Don't forgot to call Let me know if this helps :) |
Thanks for the help :) I wasnt calling BTW, I had to get a local copy of the gem and increase the dependency version on Do you know of any example code of how to chain queries so a spatial and other kinds of queries can be combined? Is it actually possible to chain these scopes? The return value from the |
@pmackay To make the query chainable, just remove the scope :within_distance, lambda { |options|
Neo4j::ActiveBase
.new_query
.call('spatial.withinDistance({layer}, {coordinate}, {distance}) YIELD node, distance')
.params(layer: spatial_index_name,
coordinate: { lon: options[:lon], lat: options[:lat] },
distance: options[:distance])
.with(:node).where("(node:#{mapped_label_name})")
} Example: Yourmodel. within_distance('...').where(node: { some_property: 'some_value' }).pluck(:node) |
I get a following error when I run
|
@kroyagis Are you using the neo4j gem 8.0+? |
Sorry, I was using 7.2.x at the time I posted this. I upgraded to 8.0.x and it does recognize ActiveBase. I'm currently solving different problems so this can be closed! Thank you. |
Please could I clarify, is there a configuration of neo4j, neo4j-spatial, neo4jrb and neo4jrb_spatial that works for Neo4J 3.x? This issue suggests there isnt because indexes were changes for spatial procedures. Would #14 resolve this compatibility problem?
@ProGM would appreciate your input.
The text was updated successfully, but these errors were encountered: