LosManos
LosManos

Reputation: 7692

Using Neo4jclient to search for property with regex

I have a working cypher query but can't get it to work in Neo4jclient.

My cypher query is

start n=node(*) where has(n.Name) and n.Name =~ 'X.*' return n;

which returns all nodes with a Name property which starts with X.
I am on purpose not using indices or relations here.

My first childish attempt (not even using regex I plan to use) fails with timeout(!) on res.Results

var res = _client.RootNode
    .StartCypher("n")
    .Where<Meeting>(m => m.Name == "X")
    .Return<Meeting>("m");

Upvotes: 1

Views: 272

Answers (1)

Charlotte Skardon
Charlotte Skardon

Reputation: 6270

Try:

var query = _client.Cypher
    .Start("n", graphClient.RootNode)
    .Where("has(n.Name)")
    .And()
    .Where("n.Name =~ 'X.*'")
    .Return<Meeting>("n");

This worked on my machine, you'll get the results like:

var results = query.Results;

Edit: I think I've realised why yours had problems, in the beginning, you put StartCypher("n") and subsequently, use m instead of n. So Return<Meeting>("m") should be Return<Meeting>("n")

Upvotes: 4

Related Questions