コード例 #1
0
        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);
        }
コード例 #2
0
        private static IEnumerable <QueryContainer> OrphanMusts(QueryContainer container)
        {
            var lBoolQuery = container.Self().Bool;

            if (lBoolQuery == null)
            {
                return new[] { container }
            }
            ;

            return(lBoolQuery?.Must?.AsInstanceOrToListOrNull());
        }
コード例 #3
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));
        }