问题
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.
I've tried sticking it in the MATCH clause but I get invalid syntax errors:
MATCH (item:Item {...})
RETURN item
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.
回答1:
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
Make sure that your properties are indexed (= label index, not lucene index):
CREATE INDEX ON :Item(title);
CREATE INDEX ON :Item(body);
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
来源:https://stackoverflow.com/questions/22360489/passing-a-lucene-query-to-neo4j-rest-api-using-cypher-2-0