コード例 #1
0
ファイル: BaseQuery.cs プロジェクト: occ/NEST
 public static BaseQuery operator |(BaseQuery lbq, BaseQuery rbq)
 {
     var q = new BaseQuery();
     var bq = new BoolBaseQueryDescriptor();
     bq._ShouldQueries = new[] { lbq, rbq };
     q.BoolQueryDescriptor = bq;
     return q;
 }
コード例 #2
0
ファイル: BaseQuery.cs プロジェクト: mivano/NEST
        public static BaseQuery operator !(BaseQuery lbq)
        {
            var q = new BaseQuery();
            var bq = new BoolBaseQueryDescriptor();
            bq._MustNotQueries = new[] { lbq };

            q.BoolQueryDescriptor = bq;
            return q;
        }
コード例 #3
0
ファイル: BaseQuery.cs プロジェクト: romankor/NEST
        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;
        }
コード例 #4
0
ファイル: BaseQuery.cs プロジェクト: occ/NEST
        public static BaseQuery operator &(BaseQuery lbq, BaseQuery rbq)
        {
            var q = new BaseQuery();
            var bq = new BoolBaseQueryDescriptor();

            bq._MustQueries = new[] { lbq, rbq };

            if (lbq.BoolQueryDescriptor.CanJoinMust()
                && rbq.BoolQueryDescriptor.CanJoinMust())
            {
                bq._MustQueries = lbq.MergeMustQueries(rbq);
            }

            q.BoolQueryDescriptor = bq;
            return q;
        }
コード例 #5
0
ファイル: BaseQuery.cs プロジェクト: mivano/NEST
        public static BaseQuery operator &(BaseQuery lbq, BaseQuery rbq)
        {
            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;
        }
コード例 #6
0
ファイル: BaseQuery.cs プロジェクト: mivano/NEST
 private static void JoinShouldOnSide(BaseQuery lbq, BaseQuery rbq, BoolBaseQueryDescriptor bq)
 {
     bq._ShouldQueries = lbq.MergeShouldQueries(rbq);
 }
コード例 #7
0
ファイル: BaseQuery.cs プロジェクト: mivano/NEST
        public static BaseQuery operator |(BaseQuery lbq, BaseQuery rbq)
        {
            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;
        }
コード例 #8
0
		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;
		}
コード例 #9
0
		private static void JoinShouldOnSide(QueryContainer lbq, QueryContainer rbq, BoolBaseQueryDescriptor bq)
		{
			((IBoolQuery)bq).Should = lbq.MergeShouldQueries(rbq);
		}
コード例 #10
0
		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;
		}
コード例 #11
0
		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;
		}
コード例 #12
0
ファイル: BaseQuery.cs プロジェクト: rupertberk/NEST
 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;
 }
コード例 #13
0
ファイル: BaseQuery.cs プロジェクト: rupertberk/NEST
        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;
        }