public LuceneQueryPredicateExpression(LuceneQueryFieldExpression field, Expression pattern, Occur occur, QueryType queryType)
     : base(typeof(bool), (ExpressionType)LuceneExpressionType.LuceneQueryPredicateExpression)
 {
     this.field = field;
     this.pattern = pattern;
     this.occur = occur;
     this.queryType = queryType;
 }
Exemplo n.º 2
0
 public LuceneQueryPredicateExpression(LuceneQueryFieldExpression field, Expression pattern, Occur occur, QueryType queryType)
     : base(typeof(bool), (ExpressionType)LuceneExpressionType.LuceneQueryPredicateExpression)
 {
     this.field     = field;
     this.pattern   = pattern;
     this.occur     = occur;
     this.queryType = queryType;
 }
        protected override Expression VisitLuceneQueryFieldExpression(LuceneQueryFieldExpression expression)
        {
            if (expression.Type != typeof(bool) || IsAlreadyInEqualityExpression())
            {
                return base.VisitLuceneQueryFieldExpression(expression);
            }

            return Expression.MakeBinary(ExpressionType.Equal, expression, Expression.Constant(!negate));
        }
 public LuceneRangeQueryExpression(LuceneQueryFieldExpression field, Expression lower, QueryType lowerQueryType, Expression upper, QueryType upperQueryType, Occur occur)
     : base(typeof(bool), (ExpressionType)LuceneExpressionType.LuceneRangeQueryExpression)
 {
     this.field = field;
     this.lower = lower;
     this.lowerQueryType = lowerQueryType;
     this.upper = upper;
     this.upperQueryType = upperQueryType;
     this.occur = occur;
 }
        public void IgnoresWhenAlreadyInBinaryExpression()
        {
            // where doc.SomeFlag == true
            var flag = new LuceneQueryFieldExpression(typeof(bool), "SomeFlag");
            var binary = Expression.MakeBinary(ExpressionType.Equal, flag, Expression.Constant(true));

            var result = (BinaryExpression)visitor.VisitExpression(binary);

            Assert.That(result, Is.SameAs(binary));
        }
Exemplo n.º 6
0
 public LuceneRangeQueryExpression(LuceneQueryFieldExpression field, Expression lower, QueryType lowerQueryType, Expression upper, QueryType upperQueryType, Occur occur)
     : base(typeof(bool), (ExpressionType)LuceneExpressionType.LuceneRangeQueryExpression)
 {
     this.field          = field;
     this.lower          = lower;
     this.lowerQueryType = lowerQueryType;
     this.upper          = upper;
     this.upperQueryType = upperQueryType;
     this.occur          = occur;
 }
        protected override Expression VisitQuerySourceReferenceExpression(QuerySourceReferenceExpression expression)
        {
            var propertyInfo = parent.Member as PropertyInfo;

            if (propertyInfo == null)
            {
                throw new NotSupportedException("Only MemberExpression of type PropertyInfo may be used on QuerySourceReferenceExpression.");
            }

            queryField = new LuceneQueryFieldExpression(propertyInfo.PropertyType, propertyInfo.Name);
            return base.VisitQuerySourceReferenceExpression(expression);
        }
        public void Inverse()
        {
            // "where !doc.SomeFlag"
            var flag = new LuceneQueryFieldExpression(typeof(bool), "SomeFlag");
            var expression = Expression.MakeUnary(ExpressionType.Not, flag, typeof(bool));
            var result = visitor.VisitExpression(expression) as BinaryExpression;

            Assert.That(result, Is.Not.Null, "Expected BinaryExpression to be returned.");
            Assert.That(result.Left, Is.SameAs(flag));
            Assert.That(result.Right, Is.InstanceOf<ConstantExpression>());
            Assert.That(((ConstantExpression)result.Right).Value, Is.EqualTo(false));
        }
        public void ConvertEnum()
        {
            var luceneQueryFieldExpression = new LuceneQueryFieldExpression(typeof(Enum), "field_name");
            var binary = Expression.MakeBinary(ExpressionType.Equal,
                Expression.Convert(luceneQueryFieldExpression, typeof(Int32)),
                Expression.Constant(0));

            var result = (BinaryExpression)visitor.VisitExpression(binary);

            Assert.That(result.Left, Is.SameAs(luceneQueryFieldExpression));
            Assert.That(result.Right, Is.InstanceOf<ConstantExpression>());
        }
Exemplo n.º 10
0
 public bool Equals(LuceneQueryFieldExpression other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.fieldName, fieldName));
 }
        public void ConvertFlag()
        {
            // "where doc.SomeFlag"
            var expression = new LuceneQueryFieldExpression(typeof (bool), "SomeFlag");

            var result = visitor.VisitExpression(expression) as BinaryExpression;

            Assert.That(result, Is.Not.Null, "Expected BinaryExpression to be returned.");
            Assert.That(result.Left, Is.SameAs(expression));
            Assert.That(result.Right, Is.InstanceOf<ConstantExpression>());
            Assert.That(((ConstantExpression)result.Right).Value, Is.EqualTo(true));
        }
        public void Stage0_Transform()
        {
            var methodInfo = ReflectionUtility.GetMethod(() => LuceneMethods.Boost<string>(null, 0f));
            var fieldExpression = new LuceneQueryFieldExpression(typeof (string), "Name");
            const float boostAmount = 5.5f;

            // LuceneField(Name).Boost(5.5)
            var call = Expression.Call(methodInfo, fieldExpression, Expression.Constant(boostAmount));
            
            var result = visitor.VisitExpression(call);

            Assert.That(result, Is.SameAs(fieldExpression));
            Assert.That(((LuceneQueryFieldExpression)result).Boost, Is.EqualTo(boostAmount));
        }
        public void ConvertFlagNestedInCompoundBinaryRight()
        {
            // where doc.Name == "foo" || doc.SomeFlag
            var flag = new LuceneQueryFieldExpression(typeof(bool), "SomeFlag");
            var binary = Expression.MakeBinary(ExpressionType.Equal, new LuceneQueryFieldExpression(typeof(string), "Name"), Expression.Constant("foo"));
            var topBinary = Expression.MakeBinary(ExpressionType.OrElse, binary, flag);

            var result = visitor.VisitExpression(topBinary) as BinaryExpression;

            Assert.That(result, Is.Not.Null, "Expected BinaryExpression to be returned.");
            Assert.That(result.Left, Is.SameAs(binary));
            Assert.That(result.Right, Is.InstanceOf<BinaryExpression>());
            Assert.That(((BinaryExpression)result.Right).Left, Is.SameAs(flag));
            Assert.That(((BinaryExpression)result.Right).Right, Is.InstanceOf<ConstantExpression>());
        }
        public void Stage1_Transform()
        {
            visitor = new BoostMethodCallTreeVisitor(1);
            var methodInfo = ReflectionUtility.GetMethod(() => false.Boost(0f));
            var fieldExpression = new LuceneQueryFieldExpression(typeof(string), "Name");
            var query = new LuceneQueryPredicateExpression(fieldExpression, Expression.Constant("foo"), BooleanClause.Occur.SHOULD);

            const float boostAmount = 0.5f;

            // (LuceneQuery[Default](+Name:"foo")).Boost(0.5f)
            var call = Expression.Call(methodInfo, query, Expression.Constant(boostAmount));

            var result = visitor.VisitExpression(call);

            Assert.That(result, Is.SameAs(query));
            Assert.That(((LuceneQueryPredicateExpression)result).Boost, Is.EqualTo(boostAmount));
        }
 public bool Equals(LuceneQueryFieldExpression other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.fieldName, fieldName);
 }
Exemplo n.º 16
0
 public LuceneQueryPredicateExpression(LuceneQueryFieldExpression field, Expression pattern, Occur occur)
     : this(field, pattern, occur, QueryType.Default)
 {
 }
 public LuceneQueryPredicateExpression(LuceneQueryFieldExpression field, Expression pattern, Occur occur)
     : this(field, pattern, occur, QueryType.Default)
 {
 }
        public void ConvertNestedMethodCall()
        {
            // where !doc.Name.StartsWith("foo")
            var field = new LuceneQueryFieldExpression(typeof(string), "Name");
            var startsWith = Expression.Call(field, "StartsWith", null, Expression.Constant("foo"));
            var expression = Expression.MakeUnary(ExpressionType.Not, startsWith, typeof(bool));
            var result = visitor.VisitExpression(expression) as BinaryExpression;

            Assert.That(result, Is.Not.Null, "Expected BinaryExpression to be returned.");
            Assert.That(result.Left, Is.SameAs(startsWith));
            Assert.That(result.Right, Is.InstanceOf<ConstantExpression>());
            Assert.That(result.NodeType, Is.EqualTo(ExpressionType.Equal));
            Assert.That(((ConstantExpression)result.Right).Value, Is.EqualTo(false));
        }
 public LuceneRangeQueryExpression(LuceneQueryFieldExpression field, Expression lower, QueryType lowerQueryType, Expression upper, QueryType upperQueryType)
     : this(field, lower, lowerQueryType, upper, upperQueryType, Occur.MUST)
 {
 }
 protected virtual Expression VisitLuceneQueryFieldExpression(LuceneQueryFieldExpression expression)
 {
     return expression;
 }
Exemplo n.º 21
0
 public LuceneRangeQueryExpression(LuceneQueryFieldExpression field, Expression lower, QueryType lowerQueryType, Expression upper, QueryType upperQueryType)
     : this(field, lower, lowerQueryType, upper, upperQueryType, Occur.MUST)
 {
 }