Я создаю некоторый код C # для запроса к моей базе данных neo4j и отображения результатов на веб-странице, используя Cytoscape.js. Я пытаюсь выполнить этот запрос с помощью кода:
`MATCH (n) WHERE toLower(n.Name) CONTAINS toLower('spoofing') WITH n MATCH (`n)-[r]-(otherNodes) RETURN n, r, otherNodes
Когда я запускаю этот запрос через браузер neo4j, я получаю 58 узлов, 155 связей. Вот мой код C #, пытающийся выполнить тот же запрос:
strSearch = "toLower(n.Name) CONTAINS '" + txtSearchPhrase.Text.Trim().ToLower() + "'";
var test = client.Cypher
.Match("(n)")
.Where(strSearch)
.With("n")
.Match("(n)-[r]-(otherNodes)")
.Return((n, r, otherNodes) => new
{
n = n.As<NodeInfo>(),
r = Return.As<string>("type(r)"),
otherNodes = otherNodes.As<NodeInfo>() //otherNodes.CollectAs<NodeInfo>()
});
var results = test.Results.ToList();
for (int i = 0; i < results.Count; i++)
{
Type type = results[i].GetType();
//JSON node.
string strSource_id = results[i].n.Type + "_" + results[i].n.Id.ToString();
string strDest_id = results[i].otherNodes.Type + "_" + results[i].otherNodes.Id.ToString();
//Source.
clsWebJsonNode myclsWebJsonNode = new clsWebJsonNode() { Id = results[i].n.Id, id = strSource_id, label = strSource_id , title = results[i].n.Name, Type = results[i].n.Type, objBlob = results[i].n.objBlob, DescriptionSummaryObjective = results[i].n.DescriptionSummaryObjective, CVSS = results[i].n.CVSS, Status = results[i].n.Status, Abstraction = results[i].n.Abstraction };
NodeColor(ref myclsWebJsonNode);
string strNodeJson = JsonConvert.SerializeObject(myclsWebJsonNode, Newtonsoft.Json.Formatting.Indented);
myWebJson.AddNodeJson(strNodeJson);
//Destination.
myclsWebJsonNode = new clsWebJsonNode() { Id = results[i].otherNodes.Id, id = strDest_id, label = strDest_id , title = results[i].otherNodes.Name, Type = results[i].otherNodes.Type, objBlob = results[i].otherNodes.objBlob, DescriptionSummaryObjective = results[i].otherNodes.DescriptionSummaryObjective, CVSS = results[i].otherNodes.CVSS, Status = results[i].otherNodes.Status, Abstraction = results[i].otherNodes.Abstraction };
NodeColor(ref myclsWebJsonNode);
strNodeJson = JsonConvert.SerializeObject(myclsWebJsonNode, Newtonsoft.Json.Formatting.Indented);
myWebJson.AddNodeJson(strNodeJson);
//JSON link.
clsWebJsonLink myclsWebJsonLink = new clsWebJsonLink() { target = strSource_id, source = strDest_id, label = results[i].r, id = (strSource_id + "--" + results[i].r + "--*" + strDest_id) };
string strLinkJson = JsonConvert.SerializeObject(myclsWebJsonLink, Newtonsoft.Json.Formatting.Indented);
myWebJson.AddLinkJson(strLinkJson);
}
Когда я выполняю этот код, я получаю 58 узлов, 103 связи. Кроме того, я не уверен, как на самом деле узнать, в каком «направлении» идут отношения. Я думал, что 'n' будет считаться источником (хвостом), а 'otherNodes' будет считаться местом назначения (головой). Но многие из моих направлений отношений не соответствуют тому, что отображается в браузере neo4j.
Кто-нибудь знает, что здесь происходит?