Criteria that specifies a specific field needs to start with a specific prefix.
This will only work on fields within Elasticsearch that are not analyzed as otherwise the keyword tokenizer will have removed any concept of a prefix.
Inheritance: ElasticLinq.Request.Criteria.SingleFieldCriteria
Ejemplo n.º 1
0
        public void ToStringContainsFieldAndPrefix()
        {
            var criteria = new PrefixCriteria("field", "regexp");
            var result = criteria.ToString();

            Assert.Contains(criteria.Field, result);
            Assert.Contains(criteria.Prefix.ToString(), result);
        }
Ejemplo n.º 2
0
        public void ConstructorSetsProperties()
        {
            const string expectedField = "someField";
            const string expectedPrefix = "somePrefix";

            var criteria = new PrefixCriteria(expectedField, expectedPrefix);
            
            Assert.Equal(expectedField, criteria.Field);
            Assert.Equal(expectedPrefix, criteria.Prefix);
        }
        public void AndWithMixedContentBecomesBoolWithShouldMustAndMustNot()
        {
            var expectedShould = new[] { new RangeCriteria("field1", memberInfo, RangeComparison.LessThan, 2), new RangeCriteria("field2", memberInfo, RangeComparison.GreaterThan, 4) };
            var expectedMust = new RangeCriteria("field3", memberInfo, RangeComparison.LessThan, 2);
            var expectedMustNot = new PrefixCriteria("field5", "prefix");

            var actual = QueryCriteriaRewriter.Compensate(AndCriteria.Combine(OrCriteria.Combine(expectedShould), expectedMust, NotCriteria.Create(expectedMustNot)));

            var boolActual = Assert.IsType<BoolCriteria>(actual);

            Assert.Equal(boolActual.Should.AsEnumerable(), expectedShould);
            Assert.Single(boolActual.Must, expectedMust);
            Assert.Single(boolActual.MustNot, expectedMustNot);
        }
 static JObject Build(PrefixCriteria criteria)
 {
     return new JObject(new JProperty(criteria.Name, new JObject(new JProperty(criteria.Field, criteria.Prefix))));
 }
Ejemplo n.º 5
0
        public void NamePropertyIsPrefix()
        {
            var criteria = new PrefixCriteria("field", "aprefix");

            Assert.Equal("prefix", criteria.Name);
        }
        public void BodyContainsPrefixFilter()
        {
            const string expectedField = "motor";
            const string expectedPrefix = "SR20";
            var prefixCriteria = new PrefixCriteria(expectedField, expectedPrefix);

            var formatter = new SearchRequestFormatter(defaultConnection, mapping, new SearchRequest { DocumentType = "type1", Filter = prefixCriteria });
            var body = JObject.Parse(formatter.Body);

            var actualRegexp = body.TraverseWithAssert("query", "filtered", "filter", "prefix", expectedField);
            Assert.Equal(expectedPrefix, actualRegexp);
        }