Neo4j 自动索引、遗留索引和标签模式:相对于节点的全文搜索的差异 [英] Neo4j auto-index, legacy index and label schema: differences for a relative-to-a-node full-text search

查看:29
本文介绍了Neo4j 自动索引、遗留索引和标签模式:相对于节点的全文搜索的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题在neo4j-legacy-indexes-and-auto-index-vs-new-label-bases-schema-indexesthe-difference-between-legacy-索引自动索引和新的索引方法

我还不能对它们发表评论并在这里写一个新线程.在我的数据库中,我有一个旧索引主题"和标签主题".

I can't comment on them yet and write a new thread here. In my db, I have a legacy index 'topic' and label 'Topic'.

我知道:

  • 一个.pattern MATCH (n:Label) 将扫描节点;
  • b.模式 START (n:Index) 将搜索旧索引
  • c.auto-index 是一种遗留索引,应该给出与 (b) 相同的结果,但在我的情况下不是
  • d.START 子句应替换为 MATCH 以表示良好做法".

a 之间的结果不一致.和 b.(见下文),无法弄清楚如何使用 MATCH 的正确语法来搜索标签的索引.

I have inconsistent results between a. and b. (see below), cannot figure out how to use proper syntax with MATCH for searching on indexing insted of labels.

这里有一些例子:

1#

start n=node:topic('name:(keyword1 AND keyword2)') return n

6 行,3 毫秒

start n=node:node_auto_index('name:(keyword1 AND keyword2)') return n;

0 行

MATCH (n:Topic) where n.name =~ '(?i).*keyword1*.AND.*keyword2*.' return n;

0 行,10K 毫秒

2#

start n=node:topic('name:(keyword1)') return n

212 行,122 毫秒 [所有包含子字符串关键字 1 的连贯结果]

212 rows, 122 ms [all coherent results containing substring keyword1]

start n=node:node_auto_index('name:(keyword1)') return n

0 行

MATCH (n:Topic) where n.name =~ '(?i).*keyword1*.'return n

835 行,8K ms [结果也不一致,包含子字符串 eyword]

835 rows, 8K ms [also results not coherent, containing substring eyword]

MATCH (n:Topic) where n.name =~ 'keyword1' return n;

1 行,>6K ms [精确匹配]

1 row, >6K ms [exact match]

MATCH (n:topic) where n.name =~ 'keyword1' return n;

没有结果(这里我使用了索引主题"而不是标签主题"!)

no results (here I used an index 'topic' not a label 'Topic'!)

MATCH (node:topic) where node.name =~ 'keyword1' return node;

没有结果(尝试直接使用节点对象",如自动索引语法)

no results (attempt to use node "object" directly, as in auto-index syntax)

你能帮忙解释一下吗:

  • 遗留索引和自动索引有什么区别,为什么两者之间的结果不一致?

  • What's the difference between a legacy index and auto-index and why inconsistent results between the two?

如何将 MATCH 子句与索引而不是标签一起使用?我想重现全文搜索的结果.

How to use MATCH clause with Indexes rather than labels? I want to reproduce results of full-text search.

哪种语法只应用于节点的邻居而不是完整数据库?比赛 ?START 子句?遗留索引?标签?我很困惑.

Which syntax to do a full-text search applied to ONLY the neighbor of a node, not the full-db? MATCH ? START clause? legacy-index ? label? I am confused.

推荐答案

自动索引(只有一个)是一个名为 node_auto_index 的手动(也称为旧版)索引.这个特殊的索引通过连接到事务处理来跟踪图表的变化.因此,如果您将 name 声明为配置中节点的自动索引的一部分,则对具有 name 属性的节点的任何更改都会反映到该索引.

The auto index (there is only one) is a manual (aka legacy) index having the name node_auto_index. This special index tracks changes to the graph by hooking into the transaction processing. So if you declared name as part of your auto index for nodes in the config, any change to a node having a name property is reflected to that index.

请注意,当您添加例如自动索引时,自动索引不会自动填充到现有数据集上.用于自动索引的新属性.

Note that auto indexes do not automatically populate on an existing dataset when you add e.g. a new property for auto indexing.

进一步注意,手动或自动索引完全独立于标签.

Note further that manual or auto indexes are totally independent of labels.

查询手动或自动索引的唯一方法是使用 START 子句:

The only way to query a manual or auto index is by using the START clause:

START n=node:<indexName>(<lucene query expression>) // index query
START n=node:<indexName>(key='<value>') // exact index lookup

Schema 索引完全不同,并在适当的时候在 MATCH 中使用.

Schema indexes are completely different and are used in MATCH when appropriate.

我的一篇博文涵盖了 neo4j 的所有索引能力.

A blog post of mine covers all the index capabilities of neo4j.

通常,您使用图形数据库中的索引来标识遍历的起点.一旦您在图表中获得参考,您只需遵循关系并且不再进行索引查找.

In general you use an index in graph databases to identify the start points for traversals. Once you've got a reference inside the graph you just follow relationships and do no longer do index lookups.

有关全文索引,请参阅 另一篇博文.

For full text indexing, see another blog post.

事实上 MATCH (p:Topic {name: 'DNA'}) RETURN pMATCH (n:Topic) where n.name = 'DNA' return n 两者是等价的.两者都会产生相同的查询计划.如果标签 Topic 和属性 name 上有模式索引(通过 CREATE INDEX ON :Topic(name)),Cypher 将隐式使用模式索引来查找指定的节点.

In fact MATCH (p:Topic {name: 'DNA'}) RETURN p and MATCH (n:Topic) where n.name = 'DNA' return n are both equvalent. Both result in the same query plan. If there is a schema index on label Topic and property name (by CREATE INDEX ON :Topic(name)) Cypher will implicitly use the schema index to find the specified node(s).

目前您无法使用基于架构索引的全文搜索.全文仅在手动/自动索引中可用.

At the moment you cannot use full text searches based on schema indexes. Full text is only available in manual / auto indexing.

您随 START n=node:topic(...) 提供的所有示例都依赖于手动索引.您有责任使它们与您的图表内容保持同步,因此我认为这些差异是由于图表中的修改不一致,而不是反映对手动索引的更改.

All the example you've provided with START n=node:topic(...) rely on a manual index. It's your responsibility to keep them in sync with your graph contents, so I assume the differences are due to inconsistent modifications in the graph and not reflecting the change to the manual index.

在任何情况下,如果您使用 START n=node:topic(....) 将永远不会使用架构索引.

In any case if you use START n=node:topic(....) will never use a schema index.

这篇关于Neo4j 自动索引、遗留索引和标签模式:相对于节点的全文搜索的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆