protected JObject Build(BoolCriteria criteria)
 {
     return(new JObject(
                new JProperty(criteria.Name,
                              new JObject(
                                  new JProperty("must", new JArray(criteria.Must.Select(token => this.Build(token as dynamic)))),
                                  new JProperty("must_not", new JArray(criteria.MustNot.Select(token => this.Build(token as dynamic)))),
                                  new JProperty("should", new JArray(criteria.Should.Select(token => this.Build(token as dynamic)))),
                                  new JProperty("minimum_should_match", 1)
                                  )
                              )
                ));
 }
        public void BodyContainsBoolMustNotQuery()
        {
            var rangeCriteria = new RangeCriteria("ranged", memberInfo, RangeComparison.GreaterThanOrEqual, 88);
            var boolMust      = new BoolCriteria(null, null, new[] { rangeCriteria });

            var formatter = new SearchRequestFormatter(defaultConnection, mapping, new SearchRequest {
                IndexType = "type1", Query = boolMust
            });
            var body = JObject.Parse(formatter.Body);

            var mustNotItems = body.TraverseWithAssert("query", "bool", "must_not");

            Assert.Equal(1, mustNotItems.Count());
            mustNotItems[0].TraverseWithAssert("range");
        }
示例#3
0
        IEnumerable <JProperty> BuildProperties(BoolCriteria criteria)
        {
            if (criteria.Must.Any())
            {
                yield return(new JProperty("must", new JArray(criteria.Must.Select(Build))));
            }

            if (criteria.MustNot.Any())
            {
                yield return(new JProperty("must_not", new JArray(criteria.MustNot.Select(Build))));
            }

            if (criteria.Should.Any())
            {
                yield return(new JProperty("should", new JArray(criteria.Should.Select(Build))));

                yield return(new JProperty("minimum_should_match", 1));
            }
        }
        public void BodyContainsBoolShouldQuery()
        {
            var range1   = new RangeCriteria("range1", memberInfo, RangeComparison.GreaterThanOrEqual, 88);
            var range2   = new RangeCriteria("range2", memberInfo, RangeComparison.GreaterThanOrEqual, 88);
            var boolMust = new BoolCriteria(null, new[] { range1, range2 }, null);

            var formatter = new SearchRequestFormatter(defaultConnection, mapping, new SearchRequest {
                IndexType = "type1", Query = boolMust
            });
            var body = JObject.Parse(formatter.Body);

            var boolBody = body.TraverseWithAssert("query", "bool");

            var minMatch = boolBody.TraverseWithAssert("minimum_should_match");

            Assert.Equal(1, minMatch.Value <int>());

            var mustNotItems = boolBody.TraverseWithAssert("should");

            Assert.Equal(2, mustNotItems.Count());
            mustNotItems[0].TraverseWithAssert("range");
        }
示例#5
0
 JObject Build(BoolCriteria criteria)
 {
     return(new JObject(new JProperty(criteria.Name, new JObject(BuildProperties(criteria)))));
 }