[英]How do I convert the nodes returned when doing a path search in Neo4j?
我有一个应用程序,我正在将一堆电子书和元数据加载到 Neo4j 中,目的是生成一个 IPFS 目录树以输入到另一个应用程序中。
这是一个 rails 应用程序,所以我有一个Book
类:
class Book
include Neo4j::ActiveNode
property :title, type: String
property :author, type: String
property :created_at, type: DateTime
property :updated_at, type: DateTime
has_many :in, :contexts, type: :FOR
has_one :out, :cover, type: :CVR, model_class: :Content
has_one :out, :content, type: :DAT
end
在导出到 IPFS的rake 任务中,我使用以下内容来执行查询:
q = Neo4j::ActiveBase.current_session.query(
"MATCH path = (n:Context)-[s:SUB*]->(m:Context)-[f:FOR]->(o:Book) WHERE n.name = '∅' RETURN DISTINCT path LIMIT 500"
)
这是返回我想要的路径,但q.first.path.nodes.first
(和所有其他节点)是Neo4j::Core::Node
s。 我想访问我的Book
类的cover
和content
关系,但不能。 例如:
q.each do |ret|
nodes = ret.path.nodes
nodes.shift # remove ∅
book = nodes.pop
path = nodes.map(&:name)
if book.content
system('ipfs', 'files', 'cp', "/ipfs/#{book.content.ipfs_id}", "/#{path.join('/')}/index.epub")
end
⋮
一种选择是使用 uuid 来查找这本书:
book = Book.find(nodes.pop.properties[:uuid])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.