コード例 #1
0
        public Task BuildAsync <T>(QueryBuilderContext <T> ctx) where T : class, new()
        {
            var fieldValuesQuery = ctx.GetSourceAs <IFieldConditionsQuery>();

            if (fieldValuesQuery?.FieldConditions == null || fieldValuesQuery.FieldConditions.Count <= 0)
            {
                return(Task.CompletedTask);
            }

            foreach (var fieldValue in fieldValuesQuery.FieldConditions)
            {
                switch (fieldValue.Operator)
                {
                case ComparisonOperator.Equals:
                    ctx.Filter &= new TermFilter {
                        Field = fieldValue.Field, Value = fieldValue.Value
                    };
                    break;

                case ComparisonOperator.NotEquals:
                    ctx.Filter &= new NotFilter {
                        Filter = FilterContainer.From(new TermFilter {
                            Field = fieldValue.Field, Value = fieldValue.Value
                        })
                    };
                    break;

                case ComparisonOperator.IsEmpty:
                    ctx.Filter &= new MissingFilter {
                        Field = fieldValue.Field
                    };
                    break;

                case ComparisonOperator.HasValue:
                    ctx.Filter &= new ExistsFilter {
                        Field = fieldValue.Field
                    };
                    break;
                }
            }

            return(Task.CompletedTask);
        }
コード例 #2
0
        public override void BuildFilter <T>(object query, object options, ref FilterContainer container)
        {
            var fieldValuesQuery = query as IFieldConditionsQuery;

            if (fieldValuesQuery?.FieldConditions == null || fieldValuesQuery.FieldConditions.Count <= 0)
            {
                return;
            }

            foreach (var fieldValue in fieldValuesQuery.FieldConditions)
            {
                switch (fieldValue.Operator)
                {
                case ComparisonOperator.Equals:
                    container &= new TermFilter {
                        Field = fieldValue.Field, Value = fieldValue.Value
                    };
                    break;

                case ComparisonOperator.NotEquals:
                    container &= new NotFilter {
                        Filter = FilterContainer.From(new TermFilter {
                            Field = fieldValue.Field, Value = fieldValue.Value
                        })
                    };
                    break;

                case ComparisonOperator.IsEmpty:
                    container &= new MissingFilter {
                        Field = fieldValue.Field
                    };
                    break;

                case ComparisonOperator.HasValue:
                    container &= new ExistsFilter {
                        Field = fieldValue.Field
                    };
                    break;
                }
            }
        }