void ParseToken(QueryToken token)
{
switch (token.ID)
{
case TokenID.OpenParen:
DepthPush();
break;
case TokenID.CloseParen:
DepthPop();
break;
case TokenID.Not:
NodePush(new QueryListNode(Keyword.Not));
break;
case TokenID.Or:
case TokenID.And:
// Only push a node if the current_parent is not the same as this token
if (current_parent.Keyword == Keyword.Not ||
current_parent.Keyword == (token.ID == TokenID.Or ? Keyword.And : Keyword.Or))
{
var list = new QueryListNode(token.ID == TokenID.Or ? Keyword.Or : Keyword.And);
var p = current_parent.Parent;
if (p != null)
{
current_parent.Parent.RemoveChild(current_parent);
}
if (current_parent.Keyword == Keyword.Not || current_parent.ChildCount > 1)
{
list.AddChild(current_parent);
}
else
{
list.TakeChildren(current_parent);
}
current_parent = p;
NodePush(list);
}
break;
case TokenID.Term:
NodePush(QueryTermNode.ParseUserQuery(field_set, token.Term));
break;
}
}