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

查看:87
本文介绍了使用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查询.有两种查询数据的方法.第一个是将2.0语法与MATCH一起使用,但不提供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天全站免登陆