internal static QueryContainer CombineAsShould(this QueryContainer leftContainer, QueryContainer rightContainer)
		{
			QueryContainer c = null;
			var leftBool = leftContainer.Self()?.Bool;
			var rightBool = rightContainer.Self()?.Bool;
			if (TryFlattenShould(leftContainer, rightContainer, leftBool, rightBool, out c))
				return c;

			var lBoolQuery = leftContainer.Self().Bool;
			var rBoolQuery = rightContainer.Self().Bool;

			var lHasShouldQueries = lBoolQuery != null && lBoolQuery.Should.HasAny();
			var rHasShouldQueries = rBoolQuery != null && rBoolQuery.Should.HasAny();

			var lq = lHasShouldQueries ? lBoolQuery.Should : new[] { leftContainer };
			var rq = rHasShouldQueries ? rBoolQuery.Should : new[] { rightContainer };

			var shouldClauses = lq.EagerConcat(rq);
			return CreateShouldContainer(shouldClauses);
		}
        internal static QueryContainer CombineAsMust(this QueryContainer leftContainer, QueryContainer rightContainer)
        {
            QueryContainer c;
            var            leftBool  = leftContainer.Self()?.Bool;
            var            rightBool = rightContainer.Self()?.Bool;

            //neither side is a bool, no special handling needed wrap in a bool must
            if (leftBool == null && rightBool == null)
            {
                return(CreateMustContainer(new Containers {
                    leftContainer, rightContainer
                }));
            }

            else if (TryHandleBoolsWithOnlyShouldClauses(leftContainer, rightContainer, leftBool, rightBool, out c))
            {
                return(c);
            }
            else if (TryHandleUnmergableBools(leftContainer, rightContainer, leftBool, rightBool, out c))
            {
                return(c);
            }

            //neither side is unmergable so neither is a bool with should clauses

            var mustNotClauses = OrphanMustNots(leftContainer).EagerConcat(OrphanMustNots(rightContainer));
            var filterClauses  = OrphanFilters(leftContainer).EagerConcat(OrphanFilters(rightContainer));
            var mustClauses    = OrphanMusts(leftContainer).EagerConcat(OrphanMusts(rightContainer));

            var container = CreateMustContainer(mustClauses, mustNotClauses, filterClauses);

            return(container);
        }
예제 #3
0
        private static QueryContainer ContainerContainingBool(QueryContainer left, QueryContainer right)
        {
            var l = (left?.Self().Bool?.CreatedByBoolDsl).GetValueOrDefault();
            var r = (right?.Self().Bool?.CreatedByBoolDsl).GetValueOrDefault();

            return(l ? left : r?right : null);
        }
		private static IEnumerable<QueryContainer> MustClausesOrSelf(QueryContainer container)
		{
			var boolQuery = container.Self().Bool;
			if (boolQuery != null && boolQuery.Must.HasAny()) return boolQuery.Must;

			return boolQuery != null && boolQuery.Conditionless ? Enumerable.Empty<QueryContainer>() : new[] {container};
		}
예제 #5
0
        private static IEnumerable <QueryContainer> MustClausesOrSelf(QueryContainer container)
        {
            var boolQuery = container.Self().Bool;

            if (boolQuery != null && boolQuery.Must.HasAny())
            {
                return(boolQuery.Must);
            }

            return(boolQuery != null && boolQuery.Conditionless ? Enumerable.Empty <QueryContainer>() : new[] { container });
        }
예제 #6
0
        private static IEnumerable <QueryContainer> OrphanMusts(QueryContainer container)
        {
            var lBoolQuery = container.Self().Bool;

            if (lBoolQuery == null)
            {
                return new[] { container }
            }
            ;
            return(lBoolQuery?.Must?.AsInstanceOrToListOrNull());
        }
예제 #7
0
        private static QueryContainer CreateMustContainer(List <QueryContainer> mustClauses, QueryContainer reuse)
        {
            var existingBool = reuse?.Self().Bool;

            if (existingBool != null && existingBool.CreatedByBoolDsl)
            {
                existingBool.Must = mustClauses.ToListOrNullIfEmpty();
                return(reuse);
            }
            return(new QueryContainer(new BoolQuery(createdByBoolDsl: true)
            {
                Must = mustClauses.ToListOrNullIfEmpty()
            }));
        }
예제 #8
0
        internal static QueryContainer CombineAsShould(this QueryContainer leftContainer, QueryContainer rightContainer)
        {
            QueryContainer c         = null;
            var            leftBool  = leftContainer.Self()?.Bool;
            var            rightBool = rightContainer.Self()?.Bool;

            if (TryFlattenShould(leftContainer, rightContainer, leftBool, rightBool, out c))
            {
                return(c);
            }

            var lBoolQuery = leftContainer.Self().Bool;
            var rBoolQuery = rightContainer.Self().Bool;

            var lHasShouldQueries = lBoolQuery != null && lBoolQuery.Should.HasAny();
            var rHasShouldQueries = rBoolQuery != null && rBoolQuery.Should.HasAny();

            var lq = lHasShouldQueries ? lBoolQuery.Should : new[] { leftContainer };
            var rq = rHasShouldQueries ? rBoolQuery.Should : new[] { rightContainer };

            var shouldClauses = lq.EagerConcat(rq);

            return(CreateShouldContainer(shouldClauses));
        }
		internal static QueryContainer CombineAsShould(this QueryContainer leftContainer, QueryContainer rightContainer)
		{
			if (!leftContainer.CanMergeShould() || !leftContainer.CanMergeShould())
				return CreateShouldContainer(new List<QueryContainer> { leftContainer, rightContainer });

			var lBoolQuery = leftContainer.Self().Bool;
			var rBoolQuery = rightContainer.Self().Bool;

			var lHasShouldQueries = lBoolQuery != null && lBoolQuery.Should.HasAny();
			var rHasShouldQueries = rBoolQuery != null && rBoolQuery.Should.HasAny();

			var lq = lHasShouldQueries ? lBoolQuery.Should : new[] { leftContainer };
			var rq = rHasShouldQueries ? rBoolQuery.Should : new[] { rightContainer };

			var shouldClauses = lq.EagerConcat(rq);
			return CreateShouldContainer(shouldClauses);
		}
예제 #10
0
        internal static QueryContainer CombineAsShould(this QueryContainer leftContainer, QueryContainer rightContainer)
        {
            if (!leftContainer.CanMergeShould() || !leftContainer.CanMergeShould())
            {
                return(CreateShouldContainer(new List <QueryContainer> {
                    leftContainer, rightContainer
                }));
            }

            var lBoolQuery = leftContainer.Self().Bool;
            var rBoolQuery = rightContainer.Self().Bool;

            var lHasShouldQueries = lBoolQuery != null && lBoolQuery.Should.HasAny();
            var rHasShouldQueries = rBoolQuery != null && rBoolQuery.Should.HasAny();

            var lq = lHasShouldQueries ? lBoolQuery.Should : new[] { leftContainer };
            var rq = rHasShouldQueries ? rBoolQuery.Should : new[] { rightContainer };

            var shouldClauses = lq.EagerConcat(rq);

            return(CreateShouldContainer(shouldClauses));
        }
		internal static QueryContainer CombineAsMust(this QueryContainer leftContainer, QueryContainer rightContainer)
		{
			QueryContainer c;
			var leftBool = leftContainer.Self()?.Bool;
			var rightBool = rightContainer.Self()?.Bool;

			//neither side is a bool, no special handling needed wrap in a bool must
			if (leftBool == null && rightBool == null)
				return CreateMustContainer(new Containers { leftContainer, rightContainer }, null);

			else if (TryHandleBoolsWithOnlyShouldClauses(leftContainer, rightContainer, leftBool, rightBool, out c)) return c;
			else if (TryHandleUnmergableBools(leftContainer, rightContainer, leftBool, rightBool, out c)) return c;

			//neither side is unmergable so neither is a bool with should clauses

			var mustNotClauses = OrphanMustNots(leftContainer).EagerConcat(OrphanMustNots(rightContainer));
			var filterClauses = OrphanFilters(leftContainer).EagerConcat(OrphanFilters(rightContainer));
			var mustClauses = OrphanMusts(leftContainer).EagerConcat(OrphanMusts(rightContainer));

			var container = CreateMustContainer(mustClauses, mustNotClauses, filterClauses);
			return container;
		}
		private static IEnumerable<QueryContainer> OrphanMusts(QueryContainer container)
		{
			var lBoolQuery = container.Self().Bool;
			if (lBoolQuery == null) return new[] { container };
			return lBoolQuery?.Must?.AsInstanceOrToListOrNull();
		}