diff --git a/aql/convertQuery2.go b/aql/convertQuery2.go index 59346d475f1e4cf8f4d955afa579e4569d9ef61a..30db4b8a0c2ff530cbe0c29e892a05032124ba4f 100644 --- a/aql/convertQuery2.go +++ b/aql/convertQuery2.go @@ -49,10 +49,11 @@ func (s *Service) ConvertQuery(JSONQuery *entity.IncomingQueryJSON) (*string, er } // Don't run search if we are getting empty queries from unit tests var tree []entity.Tree + var topNode entity.QueryEntityStruct if len(JSONQuery.Entities) != 0 && len(JSONQuery.Relations) != 0 { - tree = search(JSONQuery, 0) + tree, topNode = search(JSONQuery, 0) } - result := createQuery(JSONQuery, tree) + result := createQuery(JSONQuery, tree, topNode) return result, nil } @@ -61,20 +62,19 @@ createQuery generates a query based on the json file provided JSONQuery: *entity.IncomingQueryJSON, this is a parsedJSON struct holding all the data needed to form a query, Return: *string, a string containing the corresponding AQL query and an error */ -func createQuery(JSONQuery *entity.IncomingQueryJSON, tree []entity.Tree) *string { - currentTree := tree[0] - output := createLetFor("result", fmt.Sprintf("e_%v", currentTree.Self.In.ID), currentTree.Self.In.Name) - for constraint := range currentTree.Self.In.Constraints { - output += createFilter(currentTree.Self.In.Constraints[constraint], fmt.Sprintf("e_%v", currentTree.Self.In.ID)) +func createQuery(JSONQuery *entity.IncomingQueryJSON, tree []entity.Tree, topNode entity.QueryEntityStruct) *string { + output := createLetFor("result", fmt.Sprintf("e_%v", topNode.ID), topNode.Name) + for constraint := range topNode.Constraints { + output += createFilter(topNode.Constraints[constraint], fmt.Sprintf("e_%v", topNode.ID)) } var subNames []string - for i := range currentTree.Children { - subQuery, subName := createQueryRecurse(JSONQuery, tree, currentTree.Children[i]) + for i := range tree[0].Children { + subQuery, subName := createQueryRecurse(JSONQuery, tree, tree[0].Children[i]) output += subQuery subNames = append(subNames, subName) } - output += createZeroFilter(append(subNames, fmt.Sprintf("e_%v", currentTree.Self.In.ID))) - output += createReturn(fmt.Sprintf("e_%v", currentTree.Self.In.ID), "", subNames) + output += createZeroFilter(append(subNames, fmt.Sprintf("e_%v", topNode.ID))) + output += createReturn(fmt.Sprintf("e_%v", topNode.ID), "", subNames) output += "let nodes = union_distinct(flatten(result[**].nodes),[])\nlet edges = union_distinct(flatten(result[**].rel),[])\nreturn {\"vertices\":nodes,\"edges\":edges}" return &output }