public override Query ToQuery(LuceneASTQueryConfiguration configuration) { var query = new BooleanQuery(); bool hasExplicitPrefix; switch (Op) { case Operator.AND: LeftNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(LeftNode, Occur.MUST, out hasExplicitPrefix)); RightNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(RightNode, Occur.MUST, out hasExplicitPrefix)); break; case Operator.OR: LeftNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(LeftNode, Occur.SHOULD, out hasExplicitPrefix)); RightNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(RightNode, Occur.SHOULD, out hasExplicitPrefix), !hasExplicitPrefix); break; case Operator.NOT: query.Add(LeftNode.ToQuery(configuration), Occur.MUST_NOT); break; case Operator.Implicit: switch (configuration.DefaultOperator) { case QueryOperator.Or: LeftNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(LeftNode, Occur.SHOULD, out hasExplicitPrefix)); RightNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(RightNode, Occur.SHOULD, out hasExplicitPrefix), !hasExplicitPrefix); break; case QueryOperator.And: LeftNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(LeftNode, Occur.MUST, out hasExplicitPrefix)); RightNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(RightNode, Occur.MUST, out hasExplicitPrefix)); break; default: throw new ArgumentOutOfRangeException("defaultOperator"); } break; case Operator.INTERSECT: LeftNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(LeftNode, Occur.MUST, out hasExplicitPrefix)); RightNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(RightNode, Occur.MUST, out hasExplicitPrefix)); break; default: throw new ArgumentOutOfRangeException(); } return(query); }
public override Query ToQuery(LuceneASTQueryConfiguration configuration) { var query = new BooleanQuery(); switch (Op) { case Operator.AND: LeftNode.AddQueryToBooleanQuery(query, configuration, LeftNode.Prefix == PrefixOperator.Minus ? Occur.MUST_NOT : Occur.MUST); RightNode.AddQueryToBooleanQuery(query, configuration, RightNode.Prefix == PrefixOperator.Minus ? Occur.MUST_NOT : Occur.MUST); break; case Operator.OR: LeftNode.AddQueryToBooleanQuery(query, configuration, LeftNode.Prefix == PrefixOperator.Plus ? Occur.MUST : Occur.SHOULD); RightNode.AddQueryToBooleanQuery(query, configuration, RightNode.Prefix == PrefixOperator.Plus ? Occur.MUST : Occur.SHOULD); break; case Operator.NOT: query.Add(LeftNode.ToQuery(configuration), Occur.MUST_NOT); break; case Operator.Implicit: switch (configuration.DefaultOperator) { case QueryOperator.Or: LeftNode.AddQueryToBooleanQuery(query, configuration, LeftNode.Prefix == PrefixOperator.Plus ? Occur.MUST : Occur.SHOULD); RightNode.AddQueryToBooleanQuery(query, configuration, RightNode.Prefix == PrefixOperator.Plus ? Occur.MUST : Occur.SHOULD); break; case QueryOperator.And: LeftNode.AddQueryToBooleanQuery(query, configuration, LeftNode.Prefix == PrefixOperator.Minus ? Occur.MUST_NOT : Occur.MUST); RightNode.AddQueryToBooleanQuery(query, configuration, RightNode.Prefix == PrefixOperator.Minus ? Occur.MUST_NOT : Occur.MUST); break; default: throw new ArgumentOutOfRangeException("defaultOperator"); } break; case Operator.INTERSECT: LeftNode.AddQueryToBooleanQuery(query, configuration, LeftNode.Prefix == PrefixOperator.Minus ? Occur.MUST_NOT : Occur.MUST); RightNode.AddQueryToBooleanQuery(query, configuration, RightNode.Prefix == PrefixOperator.Minus ? Occur.MUST_NOT : Occur.MUST); break; default: throw new ArgumentOutOfRangeException(); } return(query); }
public override void AddQueryToBooleanQuery(BooleanQuery query, LuceneASTQueryConfiguration configuration, Occur o, bool letChildrenDecide = false) { bool hasExplicitPrefix; switch (Op) { case Operator.AND: LeftNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(LeftNode, letChildrenDecide ? Occur.MUST : o, out hasExplicitPrefix)); RightNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(RightNode, Occur.MUST, out hasExplicitPrefix)); break; case Operator.OR: LeftNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(LeftNode, letChildrenDecide ? Occur.SHOULD : o, out hasExplicitPrefix)); RightNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(RightNode, Occur.SHOULD, out hasExplicitPrefix), !hasExplicitPrefix); break; case Operator.NOT: query.Add(LeftNode.ToQuery(configuration), Occur.MUST_NOT); break; case Operator.Implicit: switch (configuration.DefaultOperator) { case QueryOperator.Or: LeftNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(LeftNode, letChildrenDecide ? Occur.SHOULD : o, out hasExplicitPrefix)); RightNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(RightNode, Occur.SHOULD, out hasExplicitPrefix), !hasExplicitPrefix); break; case QueryOperator.And: LeftNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(LeftNode, letChildrenDecide ? Occur.MUST : o, out hasExplicitPrefix)); RightNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(RightNode, Occur.MUST, out hasExplicitPrefix)); break; default: throw new ArgumentOutOfRangeException("defaultOperator"); } break; case Operator.INTERSECT: LeftNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(LeftNode, letChildrenDecide ? Occur.MUST : o, out hasExplicitPrefix)); RightNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(RightNode, Occur.MUST, out hasExplicitPrefix)); break; default: throw new ArgumentOutOfRangeException(); } }
public override void AddQueryToBooleanQuery(BooleanQuery query, LuceneASTQueryConfiguration configuration, Occur o) { switch (Op) { case Operator.AND: LeftNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(LeftNode, Occur.MUST)); RightNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(RightNode, Occur.MUST)); break; case Operator.OR: LeftNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(LeftNode, Occur.SHOULD)); RightNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(RightNode, Occur.SHOULD)); break; case Operator.Implicit: switch (configuration.DefaultOperator) { case QueryOperator.Or: LeftNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(LeftNode, Occur.SHOULD)); RightNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(RightNode, Occur.SHOULD)); break; case QueryOperator.And: LeftNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(LeftNode, Occur.MUST)); RightNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(RightNode, Occur.MUST)); break; default: throw new ArgumentOutOfRangeException("defaultOperator"); } break; case Operator.INTERSECT: LeftNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(LeftNode, Occur.MUST)); RightNode.AddQueryToBooleanQuery(query, configuration, PrefixToOccurance(RightNode, Occur.MUST)); break; default: throw new ArgumentOutOfRangeException(); } }