Skip to content
Snippets Groups Projects
Commit b5333c1e authored by Leonardo Christino's avatar Leonardo Christino
Browse files

feat: support ambivalent relationship direction

parent 80dcfea4
No related branches found
No related tags found
No related merge requests found
Pipeline #127266 failed
......@@ -55,8 +55,10 @@ func getNodeCypher(JSONQuery *entityv2.NodeStruct) (string, error) {
if err != nil {
return "", err
}
if JSONQuery.Relation.Direction != "TO" {
if JSONQuery.Relation.Direction == "FROM" {
cypher += fmt.Sprintf("<-%s", relationCypher)
} else if JSONQuery.Relation.Direction == "TO" {
cypher += fmt.Sprintf("-%s", relationCypher)
} else {
cypher += fmt.Sprintf("-%s", relationCypher)
}
......@@ -88,10 +90,12 @@ func getRelationCypher(JSONQuery *entityv2.RelationStruct) (string, error) {
if err != nil {
return "", err
}
if JSONQuery.Direction != "TO" {
if JSONQuery.Direction == "TO" {
cypher += fmt.Sprintf("->%s", nodeCypher)
} else if JSONQuery.Direction == "FROM" {
cypher += fmt.Sprintf("-%s", nodeCypher)
} else {
cypher += fmt.Sprintf("->%s", nodeCypher)
cypher += fmt.Sprintf("-%s", nodeCypher)
}
return cypher, nil
}
......
......@@ -560,6 +560,116 @@ func TestV2Like(t *testing.T) {
assert.Equal(t, trimmedAnswer, trimmedCypher)
}
func TestV2Both(t *testing.T) {
query := []byte(`{
"databaseName": "neo4j",
"query": [
{
"ID": "path_0",
"node": {
"ID": "id_1691576718400",
"label": "Employee",
"relation": {
"ID": "id_1691576720177",
"label": "REPORTS_TO",
"direction": "BOTH",
"node": {}
}
}
}
],
"limit": 500,
"return": [
"*"
],
"logic": [
"Like",
"@id_1691576718400.title",
"\"ale\""
]
}`)
var JSONQuery entityv2.IncomingQueryJSON
err := json.Unmarshal(query, &JSONQuery)
if err != nil {
fmt.Println(err)
t.Log(err)
}
s := NewService()
cypher, _, err := s.ConvertQuery(&JSONQuery)
if err != nil {
fmt.Println(err)
t.Log(err)
}
t.Log(*cypher)
answer := `MATCH path_0 = ((id_1691576718400:Employee)-[id_1691576720177:REPORTS_TO]-())
WHERE (id_1691576718400.title =~ (".*" + "ale" + ".*"))
RETURN * LIMIT 500`
fmt.Printf("Cypher: %s\n", answer)
trimmedCypher := fixCypherSpaces(cypher)
trimmedAnswer := fixCypherSpaces(&answer)
assert.Equal(t, trimmedAnswer, trimmedCypher)
}
func TestV2From(t *testing.T) {
query := []byte(`{
"databaseName": "neo4j",
"query": [
{
"ID": "path_0",
"node": {
"ID": "id_1691576718400",
"label": "Employee",
"relation": {
"ID": "id_1691576720177",
"label": "REPORTS_TO",
"direction": "FROM",
"node": {}
}
}
}
],
"limit": 500,
"return": [
"*"
],
"logic": [
"Like",
"@id_1691576718400.title",
"\"ale\""
]
}`)
var JSONQuery entityv2.IncomingQueryJSON
err := json.Unmarshal(query, &JSONQuery)
if err != nil {
fmt.Println(err)
t.Log(err)
}
s := NewService()
cypher, _, err := s.ConvertQuery(&JSONQuery)
if err != nil {
fmt.Println(err)
t.Log(err)
}
t.Log(*cypher)
answer := `MATCH path_0 = ((id_1691576718400:Employee)<-[id_1691576720177:REPORTS_TO]-())
WHERE (id_1691576718400.title =~ (".*" + "ale" + ".*"))
RETURN * LIMIT 500`
fmt.Printf("Cypher: %s\n", answer)
trimmedCypher := fixCypherSpaces(cypher)
trimmedAnswer := fixCypherSpaces(&answer)
assert.Equal(t, trimmedAnswer, trimmedCypher)
}
// func TestSmallChain(t *testing.T) {
// query := []byte(`{
// "databaseName": "TweedeKamer",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment