コード例 #1
0
        private static bool TryFlattenShould(
            QueryContainer leftContainer, QueryContainer rightContainer, IBoolQuery leftBool, IBoolQuery rightBool, out QueryContainer c
            )
        {
            c = null;
            var leftCanMerge  = leftContainer.CanMergeShould();
            var rightCanMerge = rightContainer.CanMergeShould();

            if (!leftCanMerge && !rightCanMerge)
            {
                c = CreateShouldContainer(new Containers {
                    leftContainer, rightContainer
                });
            }

            //left can merge but right's bool can not instead of wrapping into a new bool we inject the whole bool into left
            else if (leftCanMerge && !rightCanMerge && rightBool != null)
            {
                leftBool.Should = leftBool.Should.AddIfNotNull(rightContainer);
                c = leftContainer;
            }
            else if (rightCanMerge && !leftCanMerge && leftBool != null)
            {
                rightBool.Should = rightBool.Should.AddIfNotNull(leftContainer);
                c = rightContainer;
            }
            return(c != null);
        }
コード例 #2
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));
        }
コード例 #3
0
		internal static QueryContainer CombineAsShould(this QueryContainer leftContainer, QueryContainer rightContainer)
		{
			if ((!leftContainer.CanMergeShould() || !rightContainer.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);
		}
コード例 #4
0
		private static bool TryFlattenShould(
			QueryContainer leftContainer, QueryContainer rightContainer, IBoolQuery leftBool, IBoolQuery rightBool, out QueryContainer c)
		{
			c = null;
			var leftCanMerge = leftContainer.CanMergeShould();
			var rightCanMerge = rightContainer.CanMergeShould();
			if (!leftCanMerge && !rightCanMerge) c = CreateShouldContainer(new Containers { leftContainer, rightContainer });

			//left can merge but right's bool can not instead of wrapping into a new bool we inject the whole bool into left
			else if (leftCanMerge && !rightCanMerge && rightBool != null)
			{
				leftBool.Should = leftBool.Should.AddIfNotNull(rightContainer);
				c = leftContainer;
			}
			else if (rightCanMerge && !leftCanMerge && leftBool != null)
			{
				rightBool.Should = rightBool.Should.AddIfNotNull(leftContainer);
				c = rightContainer;
			}
			return c != null;

		}