有没有办法使用数字比较运算符(>=、<=、<、>、...)在 Neo4j 中搜索手动索引?查看 Gremlin 索引示例,它们都倾向于呈现具有特定属性值的搜索。
假设我有大约 10M 的两种类型的关系,它们都在一个名为“property”的属性中具有数值,在第一个 double 中,在第二个 int 中。
gremlin> g.e(123).getProperty('property')
==> 1.57479276459179
现在,如果我知道确切的属性值,它是一个基于对数的双精度 pvalue,我可以很容易地找到节点
gremlin> g.idx('index_e_ASSOC').get('property', 1.57479276459179)
==> e[2421730][31493-ASSOCIATION->53378]
==> e[4885094][53378-ASSOCIATION->31493]
==> e[866409][37891-ASSOCIATION->6292]
==> e[123][6292-ASSOCIATION->37891]
相反,我想对'property'进行范围搜索,例如查找'property'> = 0 && 'property' <= 1.6的所有边。这可以用 Gremlin 做吗?看看Gremlin 用户讨论组告诉我,即使是从全文 Lucene 索引中进行通配符搜索也有点 hack,而且Neo4j API也无济于事。
编辑:在 Stackoverflow 中发现了另一个类似的问题(标题为“使用 Lucene 查询语法在 Neo4j 中进行范围查询”;新用户最多只能发布两个超链接)导致 Neo4j 文档。我通过对数值使用 ValueContext 重新创建了索引。通过遵循在 neo4j 讨论组中找到的示例(标题:将 numericRange 查询与关系查询结合起来),我可以进行如下查询
start a=node(123)
match a-[rel]-(b)
where type(rel) = "ASSOCIATION" AND rel.`property` > 1.0 AND rel.`property` < 2.0
RETURN b
LIMIT 20;
它使用范围搜索。Gremlin 的语法是什么?它应该是这样的
g.idx('index_e_ASSOC')[[property: Neo4jTokens.QUERY_HEADER + "[1.0 TO 2.0]"]].count()
这在语法上是正确的,但是即使在该范围内有具有属性的边,计数也会产生 0 结果。