Last active
August 29, 2015 14:10
-
-
Save cskardon/c59208ab13d2e8777494 to your computer and use it in GitHub Desktop.
POC for http://stackoverflow.com/questions/26818882 (wild char search when parameterized)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// http://stackoverflow.com/questions/26818882 | |
/// Neo4jClient: Wild char Search do not work when parametarized | |
/// </summary> | |
namespace Question_26818882 | |
{ | |
using Neo4jClient; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
#region Entity Classes | |
class Shipper | |
{ | |
public string Name { get; set; } | |
} | |
#endregion Entity Classes | |
public static void Main() | |
{ | |
var client = new GraphClient(new Uri("http://localhost:7474/db/data")) | |
client.Connect(); | |
Run(client); | |
} | |
public static void Run(IGraphClient client) | |
{ | |
CreateEntities(client, 20); | |
FindEntities(client, "HIP"); | |
FindEntitiesWithParams(client, "HIP"); | |
} | |
private static void CreateEntities(IGraphClient client, int number) | |
{ | |
for (int i = 0; i < number; i++) | |
{ | |
var shipper = new Shipper{Name = "Shipper_" + i, Id = i}; | |
client.Cypher.Create("(s:Shipper {shipperParam})").WithParam("shipperParam", shipper).ExecuteWithoutResults(); | |
} | |
} | |
private static void FindEntities(IGraphClient client, string filterText) | |
{ | |
var query = client.Cypher | |
.Match("(s:Shipper)") | |
.Where(string.Format("(s.Name =~ '(?i).*{0}.*')", filterText)) | |
.Return(s => s.As<Shipper>()); | |
var results = query.Results.ToList(); | |
Output(results); | |
} | |
private static void FindEntitiesWithParams(IGraphClient client, string filterText) | |
{ | |
var query = client.Cypher | |
.Match("(s:Shipper)") | |
.Where("(s.Name =~ {searchParam})") | |
.WithParam("searchParam", string.Format("(?i).*{0}.*", filterText)) | |
.Return(s => s.As<Shipper>()); | |
var results = query.Results.ToList(); | |
Output(results); | |
} | |
private static void Output(List<Shipper> shippers) | |
{ | |
Console.WriteLine("Found {0} shippers", shippers.Count); | |
foreach (var shipper in shippers) | |
Console.WriteLine(shipper.Name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment