func (s *queryShape) MakeNode(it graph.Iterator) *Node { n := Node{Id: s.nodeId} for _, tag := range it.Tagger().Tags() { n.Tags = append(n.Tags, tag) } for k, _ := range it.Tagger().Fixed() { n.Tags = append(n.Tags, k) } switch it.Type() { case graph.And: for _, sub := range it.SubIterators() { s.nodeId++ newNode := s.MakeNode(sub) if sub.Type() != graph.Or { s.StealNode(&n, newNode) } else { s.AddNode(newNode) s.AddLink(&Link{n.Id, newNode.Id, 0, 0}) } } case graph.Fixed: n.IsFixed = true for graph.Next(it) { n.Values = append(n.Values, s.qs.NameOf(it.Result())) } case graph.HasA: hasa := it.(*HasA) s.PushHasa(n.Id, hasa.dir) s.nodeId++ newNode := s.MakeNode(hasa.primaryIt) s.AddNode(newNode) s.RemoveHasa() case graph.Or: for _, sub := range it.SubIterators() { s.nodeId++ newNode := s.MakeNode(sub) if sub.Type() == graph.Or { s.StealNode(&n, newNode) } else { s.AddNode(newNode) s.AddLink(&Link{n.Id, newNode.Id, 0, 0}) } } case graph.LinksTo: n.IsLinkNode = true lto := it.(*LinksTo) s.nodeId++ newNode := s.MakeNode(lto.primaryIt) hasaID, hasaDir := s.LastHasa() if (hasaDir == quad.Subject && lto.dir == quad.Object) || (hasaDir == quad.Object && lto.dir == quad.Subject) { s.AddNode(newNode) if hasaDir == quad.Subject { s.AddLink(&Link{hasaID, newNode.Id, 0, n.Id}) } else { s.AddLink(&Link{newNode.Id, hasaID, 0, n.Id}) } } else if lto.primaryIt.Type() == graph.Fixed { s.StealNode(&n, newNode) } else { s.AddNode(newNode) } case graph.Optional: // Unsupported, for the moment fallthrough case graph.All: } return &n }