public static QueryContainer CreateReturnQuery(Action <QueryContainer, BoolBaseQueryDescriptor> modify = null) { var returnQuery = new QueryContainer(); var returnBoolQuery = new BoolBaseQueryDescriptor() { }; ((IQueryContainer)returnQuery).Bool = returnBoolQuery; if (modify != null) { modify(returnQuery, returnBoolQuery); } return(returnQuery); }
public static BaseQuery CreateReturnQuery(Action <BaseQuery, BoolBaseQueryDescriptor> modify = null) { var returnQuery = new BaseQuery(); var returnBoolQuery = new BoolBaseQueryDescriptor() { }; returnQuery.BoolQueryDescriptor = returnBoolQuery; if (modify != null) { modify(returnQuery, returnBoolQuery); } return(returnQuery); }
public static QueryContainer operator !(QueryContainer lbq) { if (lbq == null || ((IQueryContainer)lbq).IsConditionless) { var newConditionless = new QueryContainer(); ((IQueryContainer)newConditionless).IsConditionless = true; return(newConditionless); } var f = new QueryContainer(); var fq = new BoolBaseQueryDescriptor(); ((IBoolQuery)fq).MustNot = new[] { lbq }; ((IQueryContainer)f).Bool = fq; return(f); }
public static BaseQuery operator !(BaseQuery lbq) { if (lbq == null || lbq.IsConditionless) { return new BaseQuery { IsConditionless = true } } ; var q = new BaseQuery(); var bq = new BoolBaseQueryDescriptor(); bq._MustNotQueries = new[] { lbq }; q.BoolQueryDescriptor = bq; return(q); }
internal static bool CanJoinShould(this BoolBaseQueryDescriptor bq) { return(bq == null || (bq != null && bq._CanJoinShould())); }
private static void JoinShouldOnSide(BaseQuery lbq, BaseQuery rbq, BoolBaseQueryDescriptor bq) { bq._ShouldQueries = lbq.MergeShouldQueries(rbq); }
public static BaseQuery operator &(BaseQuery lbq, BaseQuery rbq) { if (lbq == null) { return(rbq); } if (rbq == null) { return(lbq); } if (lbq.IsConditionless && rbq.IsConditionless) { return new BaseQuery() { IsConditionless = true } } ; else if (lbq.IsConditionless) { return(rbq); } else if (rbq.IsConditionless) { return(lbq); } var q = new BaseQuery(); var bq = new BoolBaseQueryDescriptor(); q.BoolQueryDescriptor = bq; if (lbq.BoolQueryDescriptor == null && rbq.BoolQueryDescriptor == null) { bq._MustQueries = new[] { lbq, rbq }; return(q); } if (lbq.BoolQueryDescriptor != null && rbq.BoolQueryDescriptor != null) { if (lbq.BoolQueryDescriptor._HasOnlyMustNot() && rbq.BoolQueryDescriptor._HasOnlyMustNot()) { bq._MustQueries = null; bq._MustNotQueries = lbq.MergeMustNotQueries(rbq); } else if (lbq.BoolQueryDescriptor.CanJoinMust() && rbq.BoolQueryDescriptor.CanJoinMust()) { bq._MustQueries = lbq.MergeMustQueries(rbq); } else { bq._MustQueries = new[] { lbq, rbq } }; if (lbq.BoolQueryDescriptor.CanJoinMustNot() && rbq.BoolQueryDescriptor.CanJoinMustNot()) { bq._MustNotQueries = lbq.MergeMustNotQueries(rbq); } return(q); } if (lbq.BoolQueryDescriptor != null) { if (lbq.BoolQueryDescriptor._HasOnlyMustNot()) { bq._MustNotQueries = lbq.BoolQueryDescriptor._MustNotQueries; bq._MustQueries = new[] { rbq }; return(q); } else if (lbq.BoolQueryDescriptor.CanJoinMust()) { bq._MustQueries = lbq.MergeMustQueries(rbq); } else { bq._MustQueries = new[] { lbq, rbq } }; if (lbq.BoolQueryDescriptor.CanJoinMustNot()) { bq._MustNotQueries = lbq.MergeMustNotQueries(rbq); } return(q); } if (rbq.BoolQueryDescriptor._HasOnlyMustNot()) { bq._MustNotQueries = rbq.BoolQueryDescriptor._MustNotQueries; bq._MustQueries = new[] { lbq }; return(q); } if (rbq.BoolQueryDescriptor.CanJoinMust()) { bq._MustQueries = rbq.MergeMustQueries(lbq); } else { bq._MustQueries = new[] { rbq, lbq } }; if (rbq.BoolQueryDescriptor.CanJoinMustNot()) { bq._MustNotQueries = rbq.MergeMustNotQueries(lbq); } return(q); }
public static BaseQuery operator |(BaseQuery lbq, BaseQuery rbq) { if (lbq == null) { return(rbq); } if (rbq == null) { return(lbq); } if (lbq.IsConditionless && rbq.IsConditionless) { return new BaseQuery() { IsConditionless = true } } ; else if (lbq.IsConditionless) { return(rbq); } else if (rbq.IsConditionless) { return(lbq); } var q = new BaseQuery(); var bq = new BoolBaseQueryDescriptor(); bq._ShouldQueries = new[] { lbq, rbq }; q.BoolQueryDescriptor = bq; if (lbq.BoolQueryDescriptor == null && rbq.BoolQueryDescriptor == null) { bq._ShouldQueries = lbq.MergeShouldQueries(rbq); return(q); } else if (lbq.BoolQueryDescriptor != null && rbq.BoolQueryDescriptor == null) { JoinShouldOnSide(lbq, rbq, bq); } else if (rbq.BoolQueryDescriptor != null && lbq.BoolQueryDescriptor == null) { JoinShouldOnSide(rbq, lbq, bq); } else { if (lbq.BoolQueryDescriptor.CanJoinShould() && rbq.BoolQueryDescriptor.CanJoinShould()) { bq._ShouldQueries = lbq.MergeShouldQueries(rbq); } else { bq._ShouldQueries = new[] { lbq, rbq } }; } return(q); }
internal static bool CanMergeMustAndMustNots(this BoolBaseQueryDescriptor bq) { return(bq == null || !bq._ShouldQueries.HasAny()); }
private static void JoinShouldOnSide(QueryContainer lbq, QueryContainer rbq, BoolBaseQueryDescriptor bq) { ((IBoolQuery)bq).Should = lbq.MergeShouldQueries(rbq); }
public static QueryContainer operator |(QueryContainer leftQuery, QueryContainer rightQuery) { var defaultQuery = new QueryContainer(); ((IQueryContainer)defaultQuery).IsConditionless = true; leftQuery = leftQuery ?? defaultQuery; rightQuery = rightQuery ?? defaultQuery; var combined = new[] { leftQuery, rightQuery }; if (combined.Any(bf => ((IQueryContainer)bf).IsConditionless)) { return(combined.FirstOrDefault(bf => !((IQueryContainer)bf).IsConditionless) ?? defaultQuery); } var leftBoolQuery = ((IQueryContainer)leftQuery).Bool; var rightBoolQuery = ((IQueryContainer)rightQuery).Bool; var f = new QueryContainer(); var fq = new BoolBaseQueryDescriptor(); ((IBoolQuery)fq).Should = new[] { leftQuery, rightQuery }; ((IQueryContainer)f).Bool = fq; var mergeLeft = !((IQueryContainer)leftQuery).IsStrict && (leftBoolQuery == null || ((IBoolQuery)leftBoolQuery).MinimumShouldMatch == null); var mergeRight = !((IQueryContainer)rightQuery).IsStrict && (rightBoolQuery == null || ((IBoolQuery)rightBoolQuery).MinimumShouldMatch == null); //if neither the left nor the right side represent a bool query join them if (((IQueryContainer)leftQuery).Bool == null && ((IQueryContainer)rightQuery).Bool == null) { ((IBoolQuery)fq).Should = leftQuery.MergeShouldQueries(rightQuery); return(f); } //if the left or right sight already is a bool query join the non bool query side of the //of the operation onto the other. if (((IQueryContainer)leftQuery).Bool != null && ((IQueryContainer)rightQuery).Bool == null && mergeLeft) { JoinShouldOnSide(leftQuery, rightQuery, fq); } else if (((IQueryContainer)rightQuery).Bool != null && ((IQueryContainer)leftQuery).Bool == null && mergeRight) { JoinShouldOnSide(rightQuery, leftQuery, fq); } //both sides already represent a bool query else { //both sides report that we may merge the shoulds if (mergeLeft && mergeRight && leftBoolQuery.CanJoinShould() && rightBoolQuery.CanJoinShould()) { ((IBoolQuery)fq).Should = leftQuery.MergeShouldQueries(rightQuery); } else { //create a new nested bool with two separate should bool sections ((IBoolQuery)fq).Should = new[] { leftQuery, rightQuery } }; } return(f); }
public static BaseQuery operator |(BaseQuery leftQuery, BaseQuery rightQuery) { var defaultQuery = new BaseQuery() { IsConditionless = true }; leftQuery = leftQuery ?? defaultQuery; rightQuery = rightQuery ?? defaultQuery; var combined = new[] { leftQuery, rightQuery }; if (combined.Any(bf => bf.IsConditionless)) { return(combined.FirstOrDefault(bf => !bf.IsConditionless) ?? defaultQuery); } var leftBoolQuery = leftQuery.BoolQueryDescriptor; var rightBoolQuery = rightQuery.BoolQueryDescriptor; var f = new BaseQuery(); var fq = new BoolBaseQueryDescriptor(); fq._ShouldQueries = new[] { leftQuery, rightQuery }; f.BoolQueryDescriptor = fq; var mergeLeft = !leftQuery.IsStrict && (leftBoolQuery == null || leftBoolQuery._MinimumNumberShouldMatches == null); var mergeRight = !rightQuery.IsStrict && (rightBoolQuery == null || rightBoolQuery._MinimumNumberShouldMatches == null); //if neither the left nor the right side represent a bool query join them if (leftQuery.BoolQueryDescriptor == null && rightQuery.BoolQueryDescriptor == null) { fq._ShouldQueries = leftQuery.MergeShouldQueries(rightQuery); return(f); } //if the left or right sight already is a bool query join the non bool query side of the //of the operation onto the other. if (leftQuery.BoolQueryDescriptor != null && rightQuery.BoolQueryDescriptor == null && mergeLeft) { JoinShouldOnSide(leftQuery, rightQuery, fq); } else if (rightQuery.BoolQueryDescriptor != null && leftQuery.BoolQueryDescriptor == null && mergeRight) { JoinShouldOnSide(rightQuery, leftQuery, fq); } //both sides already represent a bool query else { //both sides report that we may merge the shoulds if (mergeLeft && mergeRight && leftBoolQuery.CanJoinShould() && rightBoolQuery.CanJoinShould()) { fq._ShouldQueries = leftQuery.MergeShouldQueries(rightQuery); } else { //create a new nested bool with two separate should bool sections fq._ShouldQueries = new[] { leftQuery, rightQuery } }; } return(f); }