简体   繁体   English

标签,属性或节点? Cypher支架/ Neo4j的

[英]Labels, properties, or nodes? Cypher/Neo4j

I can't quite tell if this is a bad question, but I think it has a definitive answer... 我不太清楚这是一个不好的问题,但我认为它有一个明确的答案...

I'm work on building my first graph database. 我正在构建我的第一个图形数据库。 It will hold nodes that are references to content. 它将包含引用内容的节点。 These nodes will be connected to term nodes. 这些节点将连接到术语节点。 Each term node can be one of about seven types (Person, Organization, Jargon etc). 每个术语节点可以是大约七种类型(人员,组织,专业术语等)之一。

What is the best way to implement the types of terms in the database as it relates to query speed? 在数据库中实现与查询速度相关的术语类型的最佳方法是什么? Users will search for content based on the terms and the idea is to allow them to filter the terms based on their types. 用户将根据术语搜索内容,其想法是允许他们根据其类型来过滤术语。

As a property seems out of the question as it would require accessing a JSON object for every term during a query. 由于属性似乎是不可能的,因为它要求在查询期间为每个术语访问JSON对象。

(contentNode:content)-[:TAGGED_WITH]-(termNode:term {type: {"people":false,"organizations":false,"physicalObjects":true,"concepts":true,...}}

Labels intuitively make sense to me as the different types really are just labeling the term nodes more specifically. 标签对我来说很直观,因为不同的类型实际上只是在更具体地标记节点。 Each term node could have the label 'term' as well as the relevant types. 每个术语节点可以具有标签“术语”以及相关类型。 I have some confusion about this, but it seems labels cannot be used as dynamic properties in a cypher query as it prevents the query from being cached/properly indexed. 我对此有些困惑,但是似乎标签不能在密码查询中用作动态属性,因为它阻止查询被缓存/正确索引。

(contentNode:content)-[:TAGGED_WITH]-(termNode:term:physicalObject:jargon:...)

The last option I can think of would be to have a node for each of the term 'types' and connect the term to the relevant type nodes. 我能想到的最后一个选择是为每个术语“类型”都有一个节点,并将该术语连接到相关的类型节点。 Right now this is seeming like the best option (despite being the most verbose). 目前,这似乎是最好的选择(尽管最冗长)。

(contentNode:content)-[:TAGGED_WITH]-(termNode:term)-[:IS_TYPE]-(typeNode:termType {name:jargon}), (termNode:term)-[:IS_TYPE]-(typeNode:termType {name:physical object}), (termNode:term)-[:IS_TYPE]-(typeNode:termType {name: ...})

Can anyone with more experience/knowledge weigh in on this? 任何有更多经验/知识的人都可以参与其中吗? Thanks a lot. 非常感谢。

I'm not sure I completely understand what you're trying to do but I wanted to answer a few of the points and then maybe you can elaborate: 我不确定我是否完全理解您要做什么,但我想回答几点,然后也许您可以阐述一下:

but it seems labels cannot be used as dynamic properties in a cypher query as it prevents the query from being cached/properly indexed. 但似乎标签不能在密码查询中用作动态属性,因为它会阻止查询被缓存/正确索引。

Using dynamic labels won't have an impact on indexing but you're partially write about the caching. 使用动态标签不会对索引产生影响,但是您只写了部分有关缓存的文章。 The cypher parser keeps a cache of queries that it's seen before so that it doesn't have to regenerate the query plan each time. 密码解析器保留了以前见过的查询缓存,因此不必每次都重新生成查询计划。 Given that you only have a limited number of labels it wouldn't take long until you've cached all combinations anyway. 由于标签数量有限,因此只要您缓存了所有组合,就不会花很长时间。

I would suggest trying out the various models with a subset of your data and measure the query time & query readability for each. 我建议尝试使用您的数据子集尝试各种模型,并分别测量每个模型的查询时间和查询可读性。

Mark 标记

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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