Neo4j中的标签和索引是什么?

时间:2022-06-28 23:20:13

I am using neo4j-core gem (Neo4j::Node API). It is the only MRI-compatible Ruby binding of neo4j that I could find, and hence is valuable, but its documentation is a crap (it has missing links, lots of typographical errors, and is difficult to comprehend). In the Label and Index Support section of the first link, it says:

我正在使用Neo4j -core gem (Neo4j::Node API)。它是我能找到的唯一兼容mri的neo4j Ruby绑定,因此很有价值,但是它的文档是一个垃圾(它缺少链接,有很多排版错误,而且很难理解)。在第一个链接的标签和索引支持部分,它说:

  • Create a node with an [sic] label person and one property

    使用[sic]标签人和一个属性创建一个节点

    Neo4j::Node.create({name: 'kalle'}, :person)
    
  • Add index on a label

    在标签上添加索引

    person = Label.create(:person)
    person.create_index(:name)
    
  • drop index

    指数下降

    person.drop_index(:name)
    

(whose second code line I believe is a typographical error of the following)

(我认为他的第二个代码行是以下的排版错误)

person = Node4j::Label.create(:person)
  • What is a label, is it the name of a database table, or is it an attribute peculiar to a node?
  • 什么是标签,它是数据库表的名称,还是节点特有的属性?
  • If it is the name of a node, I don't under the fact that (according to the API in the second link) the method Neo4j::Node.create and Neo4j::Node#add_label can take multiple arguments for the label. What does it mean to have multiple labels on a node?
  • 如果它是一个节点的名称,那么我不知道(根据第二个链接的API)该方法Neo4j:: node。create和Neo4j::Node#add_label可以为标签接受多个参数。在一个节点上有多个标签意味着什么?
  • Furthermore, If I repeat the create command with the same label argument, it creates a different node object each time. What does it mean to have multiple nodes with the same name? Isn't a label something to identify a node?
  • 此外,如果我使用相同的label参数重复创建命令,那么每次都会创建不同的节点对象。拥有多个名称相同的节点意味着什么?标签不是用来识别节点的东西吗?
  • What is index? How are labels and indices different?
  • 索引是什么?标签和索引有何不同?

2 个解决方案

#1


4  

Labels are a way of grouping nodes. You can give the label to many nodes or just one node. Think of it as a collection of nodes that are grouped together. They allow you to assign indexes and other constraints.

标签是对节点进行分组的一种方式。您可以给许多节点或仅仅一个节点一个标签。可以将它看作是分组在一起的节点的集合。它们允许您分配索引和其他约束。

An index allows quick lookup of nodes or edges without having to traverse the entire graph to find them. Think of it as a table of direct pointers to the particular nodes/edges indexed.

索引允许快速查找节点或边,而不必遍历整个图来查找它们。可以把它看作是指向索引的特定节点/边的直接指针的表。

#2


2  

As I read what you pasted from the docs (and without, admittedly, knowing the slightest thing about neo4j):

当我读到您从文档中粘贴的内容时(当然,不需要知道关于neo4j的最细微之处):

  • It's a graph database, where every piece of data is a node with a certain amount of properties.

    它是一个图形数据库,每个数据块都是具有一定属性的节点。

  • Each node can have a label (or more, presumably?). Think of it as a type -- or perhaps more appropriately, in Ruby parlance, a Module.

    每个节点都可以有一个标签(或者可能更多)。可以把它看作一种类型——或者用Ruby的话说,更恰当地说,它是一个模块。

  • It's a database, so nodes can be part of an index for quicker access. So can subsets of nodes, and therefor nodes with a certain label.

    它是一个数据库,因此节点可以作为索引的一部分,以便更快地访问。节点的子集也可以,对于有特定标签的节点。

Put another way: Think of the label as the table in a DB. Nodes as DB rows, which can belong to one or more labels/tables, or no label/table at all for that matter. And indexes as DB indexes on sets of rows.

换句话说:把标签看作DB中的表。作为DB行的节点,它可以属于一个或多个标签/表,或者根本不属于任何标签/表。并将索引作为DB索引放在一组行上。

#1


4  

Labels are a way of grouping nodes. You can give the label to many nodes or just one node. Think of it as a collection of nodes that are grouped together. They allow you to assign indexes and other constraints.

标签是对节点进行分组的一种方式。您可以给许多节点或仅仅一个节点一个标签。可以将它看作是分组在一起的节点的集合。它们允许您分配索引和其他约束。

An index allows quick lookup of nodes or edges without having to traverse the entire graph to find them. Think of it as a table of direct pointers to the particular nodes/edges indexed.

索引允许快速查找节点或边,而不必遍历整个图来查找它们。可以把它看作是指向索引的特定节点/边的直接指针的表。

#2


2  

As I read what you pasted from the docs (and without, admittedly, knowing the slightest thing about neo4j):

当我读到您从文档中粘贴的内容时(当然,不需要知道关于neo4j的最细微之处):

  • It's a graph database, where every piece of data is a node with a certain amount of properties.

    它是一个图形数据库,每个数据块都是具有一定属性的节点。

  • Each node can have a label (or more, presumably?). Think of it as a type -- or perhaps more appropriately, in Ruby parlance, a Module.

    每个节点都可以有一个标签(或者可能更多)。可以把它看作一种类型——或者用Ruby的话说,更恰当地说,它是一个模块。

  • It's a database, so nodes can be part of an index for quicker access. So can subsets of nodes, and therefor nodes with a certain label.

    它是一个数据库,因此节点可以作为索引的一部分,以便更快地访问。节点的子集也可以,对于有特定标签的节点。

Put another way: Think of the label as the table in a DB. Nodes as DB rows, which can belong to one or more labels/tables, or no label/table at all for that matter. And indexes as DB indexes on sets of rows.

换句话说:把标签看作DB中的表。作为DB行的节点,它可以属于一个或多个标签/表,或者根本不属于任何标签/表。并将索引作为DB索引放在一组行上。