private SectionSearchQueryPlan TranslateBooleanQuery(BooleanQuery query) { List<Query> requiredClauses = new List<Query>(); List<Query> prohibitedClauses = new List<Query>(); List<Query> optionalClauses = new List<Query>(); BooleanClause[] clauses = query.GetClauses(); foreach (BooleanClause clause in clauses) { if (clause.IsRequired) { requiredClauses.Add(clause.Query); } else if (clause.IsProhibited) { prohibitedClauses.Add(clause.Query); } else { optionalClauses.Add(clause.Query); } } SectionSearchQueryPlan positiveNode = null; SectionSearchQueryPlan negativeNode = null; if (requiredClauses.Count > 0) { if (requiredClauses.Count == 1) { positiveNode = Translate(requiredClauses.Get(0)); } else { SectionSearchQueryPlan[] subqueries = Translate(requiredClauses); if (subqueries != null && subqueries.Length > 0) positiveNode = new AndNode(subqueries); } } else if (optionalClauses.Count > 0) { if (optionalClauses.Count == 1) { positiveNode = Translate(optionalClauses.Get(0)); } else { SectionSearchQueryPlan[] subqueries = Translate(optionalClauses); if (subqueries != null && subqueries.Length > 0) positiveNode = new OrNode(subqueries); } } if (prohibitedClauses.Count > 0) { if (prohibitedClauses.Count == 1) { negativeNode = Translate(prohibitedClauses.Get(0)); } else { negativeNode = new OrNode(Translate(prohibitedClauses)); } } if (negativeNode == null) { return positiveNode; } else { if (positiveNode == null) { return new UnaryNotNode(negativeNode); } else { return new AndNotNode(positiveNode, negativeNode); } } }
private SectionSearchQueryPlan TranslateBooleanQuery(BooleanQuery query) { List <Query> requiredClauses = new List <Query>(); List <Query> prohibitedClauses = new List <Query>(); List <Query> optionalClauses = new List <Query>(); BooleanClause[] clauses = query.GetClauses(); foreach (BooleanClause clause in clauses) { if (clause.IsRequired) { requiredClauses.Add(clause.Query); } else if (clause.IsProhibited) { prohibitedClauses.Add(clause.Query); } else { optionalClauses.Add(clause.Query); } } SectionSearchQueryPlan positiveNode = null; SectionSearchQueryPlan negativeNode = null; if (requiredClauses.Count > 0) { if (requiredClauses.Count == 1) { positiveNode = Translate(requiredClauses.Get(0)); } else { SectionSearchQueryPlan[] subqueries = Translate(requiredClauses); if (subqueries != null && subqueries.Length > 0) { positiveNode = new AndNode(subqueries); } } } else if (optionalClauses.Count > 0) { if (optionalClauses.Count == 1) { positiveNode = Translate(optionalClauses.Get(0)); } else { SectionSearchQueryPlan[] subqueries = Translate(optionalClauses); if (subqueries != null && subqueries.Length > 0) { positiveNode = new OrNode(subqueries); } } } if (prohibitedClauses.Count > 0) { if (prohibitedClauses.Count == 1) { negativeNode = Translate(prohibitedClauses.Get(0)); } else { negativeNode = new OrNode(Translate(prohibitedClauses)); } } if (negativeNode == null) { return(positiveNode); } else { if (positiveNode == null) { return(new UnaryNotNode(negativeNode)); } else { return(new AndNotNode(positiveNode, negativeNode)); } } }