繁体   English   中英

在 Neo4j 中进行路径搜索时如何转换返回的节点?

[英]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

导出到 IPFSrake 任务中,我使用以下内容来执行查询:

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类的covercontent关系,但不能。 例如:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM