使用 Cypher 2.0 将 Lucene 查询传递给 Neo4j REST API [英] Passing a Lucene query to Neo4j REST API using Cypher 2.0

查看:20
本文介绍了使用 Cypher 2.0 将 Lucene 查询传递给 Neo4j REST API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个 Lucene 查询,例如 (title:"foo bar" AND body:baz*) OR title:bat 是否有任何直接的方法可以将其传递给 Cypher 查询?看起来这种用于使用 START 和旧的 node_auto_index 但我不确定如何使用 Cypher 2.0 正确执行此操作.

If I have a Lucene query such as (title:"foo bar" AND body:baz*) OR title:bat is there any straightforward way to pass this into a Cypher query? It looks like this sort of used to work with START and the old node_auto_index but I'm not sure how to do this properly with Cypher 2.0.

我已经尝试将它粘贴在 MATCH 子句中,但出现无效的语法错误:

I've tried sticking it in the MATCH clause but I get invalid syntax errors:

MATCH (item:Item {...})
RETURN item

我即将编写一个解析器,将 Lucene 查询转换为参数化的 Cypher 查询,但我想我会先检查是否有更简单的方法.

I'm about to write a parser that converts a Lucene query to a parameterized Cypher query but I thought I would check to see if there is an easier way first.

推荐答案

您是对的,您只能通过 START 使用 Lucene 查询.有两种方法可以查询您的数据.第一个是在 MATCH 中使用 2.0 语法,但没有 Lucene 支持.标签索引尚不支持通配符搜索,但应包含在未来版本中.您必须使用正则表达式来搜索通配符.因此,以下查询的性能可能无法满足您的需求.

You are correct that you can only use Lucene queries with START. There are 2 ways to query your data. The first one is to use the 2.0 syntax with MATCH, but without Lucene support. Label indexes do not yet support wildcard searches, but it should be included in a future release. You'll have to use a regex to search with wildcards. Because of this, performance with the following query might not suit your needs.

MATCH (item:Item)
WHERE (item.title = "foo bar" AND item.body =~ "ba.*") OR item.title = "bat"
RETURN item

确保您的属性已编入索引(= 标签索引,而不是 lucene 索引):

Make sure that your properties are indexed (= label index, not lucene index):

CREATE INDEX ON :Item(title); 
CREATE INDEX ON :Item(body);

如果您仍想使用 Lucene 的旧式索引,您的查询将类似于:

If you still want to use legacy indexing with Lucene, your query would be something like:

START item=node:node_auto_index("(title:'foo bar' AND body:baz*) OR title:'bat'")
RETURN item

这篇关于使用 Cypher 2.0 将 Lucene 查询传递给 Neo4j REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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