public void MemberEqualConstValueReverse()
        {
            Expression <Func <Product, bool> > exp = (Product p) => 2 == p.Price;
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("price:(2)", _serializer.Serialize(query));
        }
        public void CompareGreaterOrEqual()
        {
            Expression <Func <Product, bool> > exp = (Product p) => p.Price >= 12;
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("price:[12 TO *]", _serializer.Serialize(query));
        }
        public void NotEqualNull()
        {
            Expression <Func <Product, bool> > exp = (Product p) => p.Id != null;
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("id:[* TO *]", _serializer.Serialize(query));
        }
        public void NotConstantFalse()
        {
            Expression <Func <Product, bool> > exp = (Product p) => !false;
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("*:*", _serializer.Serialize(query));
        }
        public void MemberEqualConstFalse()
        {
            Expression <Func <Product, bool> > exp = (Product p) => p.InStock == false;
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("inStock_b:(false)", _serializer.Serialize(query));
        }
        public void DivVariable()
        {
            double qwe = 12;
            Expression <Func <Product, object> > exp = (Product p) => p.Sequence / qwe;

            Assert.Equal("div(sequence_i,12)", MemberContext.ForType <Product>().GetSolrMemberProduct(exp.Body));
        }
        public void NullableNotHasValue()
        {
            Expression <Func <Product, bool> > exp = (Product p) => !p.Popularity.HasValue;
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("(*:* NOT popularity:[* TO *])", _serializer.Serialize(query));
        }
        public void ConditionalLessThanTestMemberTrueMemberFalseMember()
        {
            Expression <Func <Product, bool> > exp = (Product p) => (p.Popularity != null ? p.Popularity.Value : p.Price) > 7;
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("(popularity:{7 TO *} OR ((*:* NOT popularity:[* TO *]) AND price:{7 TO *}))", _serializer.Serialize(query));
        }
        public void ConditionalTestMemberTrueConstTrueFalseMember()
        {
            Expression <Func <Product, bool> > exp = (Product p) => p.Popularity != null ? true : p.InStock;
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("(popularity:[* TO *] OR ((*:* NOT popularity:[* TO *]) AND inStock_b:(true)))", _serializer.Serialize(query));
        }
        public void CollectionContainsParam(string item, string expected)
        {
            Expression <Func <Product, bool> > exp = (Product p) => p.Categories.Contains(item);
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal(expected, _serializer.Serialize(query));
        }
        public void NotEqualValueReverse()
        {
            Expression <Func <Product, bool> > exp = (Product p) => "qwe" != p.Id;
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("(*:* NOT id:(qwe))", _serializer.Serialize(query));
        }
        public void CollectionContainsVar()
        {
            string i = "qwe";
            Expression <Func <Product, bool> > exp = (Product p) => p.Categories.Contains(i);
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("cat:(qwe)", _serializer.Serialize(query));
        }
        public void CollectionAnyWithoutPredicate()
        {
            int i = 2;
            Expression <Func <Product, bool> > exp = (Product p) => p.Categories.Any();
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("cat:[* TO *]", _serializer.Serialize(query));
        }
        public void CollectionAnyNotEqual()
        {
            int i = 2;
            Expression <Func <Product, bool> > exp = (Product p) => p.Categories.Any(s => s != "qwe");
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("(*:* NOT cat:(qwe))", _serializer.Serialize(query));
        }
        public void CollectionAnyContains()
        {
            string[] arr = { "q1", "q2" };
            Expression <Func <Product, bool> > exp = (Product p) => p.Categories.Any(s => arr.Contains(s));
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("(cat:((q1) OR (q2)))", _serializer.Serialize(query));
        }
        public void ConstEqualVarFalse()
        {
            int i = 2;
            Expression <Func <Product, bool> > exp = (Product p) => 3 == i;
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("(*:* NOT *:*)", _serializer.Serialize(query));
        }
        public void MemberEqualVarNullableTrue()
        {
            bool?b = true;
            Expression <Func <Product, bool> > exp = (Product p) => p.InStock == b;
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("inStock_b:(true)", _serializer.Serialize(query));
        }
        public void MemberEqualNull()
        {
            bool b = true;
            Expression <Func <Product, bool> > exp = (Product p) => p.Popularity == null;
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("(*:* NOT popularity:[* TO *])", _serializer.Serialize(query));
        }
        public void MemberEqualVarValue()
        {
            int i = 2;
            Expression <Func <Product, bool> > exp = (Product p) => p.Price == i;
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("price:(2)", _serializer.Serialize(query));
        }
        public void VarTrue()
        {
            bool b = true;
            Expression <Func <Product, bool> > exp = (Product p) => b;
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("*:*", _serializer.Serialize(query));
        }
        public void ContainsArray()
        {
            decimal[] a = { 1, 2, 3 };

            Expression <Func <Product, bool> > exp = (Product p) => a.Contains(p.Price);
            ISolrQuery query = ((LambdaExpression)exp).Body.GetSolrFilterQuery(MemberContext.ForType <Product>());

            Assert.Equal("(price:((1) OR (2) OR (3)))", _serializer.Serialize(query));
        }
        public void TransformersValue()
        {
            Expression <Func <Product, object> > exp = (Product p) => SolrExpr.Transformers.Value("qwe");

            Assert.Equal("[value v='qwe']", MemberContext.ForType <Product>().GetSolrMemberProduct(exp.Body));

            exp = (Product p) => SolrExpr.Transformers.Value(1);
            Assert.Equal("[value v=1 t=int]", MemberContext.ForType <Product>().GetSolrMemberProduct(exp.Body));
        }
Exemple #23
0
        public SolrQueryProvider(
            IExecuter <TEntity> operations,
            SolrNetLinqOptions options,
            MemberContext context,
            SelectExpressionsCollection selectExpressions)
        {
            Operations        = operations ?? throw new ArgumentNullException(nameof(operations));
            Options           = options ?? throw new ArgumentNullException(nameof(options));
            SelectExpressions = selectExpressions ?? new SelectExpressionsCollection();

            if (context == null)
            {
                this.MemberContext = MemberContext.ForType <TEntity>();
                this.MemberContext.FieldSerializer = this.Options.SolrFieldSerializer;
                this.MemberContext.MappingManager  = this.Options.MappingManager;
            }
            else
            {
                this.MemberContext = context;
            }
        }
        public void Min()
        {
            Expression <Func <Product, object> > exp = (Product p) => Math.Min(p.Sequence, 11);

            Assert.Equal("min(sequence_i,11)", MemberContext.ForType <Product>().GetSolrMemberProduct(exp.Body));
        }
        public void Log()
        {
            Expression <Func <Product, object> > exp = (Product p) => Math.Log10(p.Sequence);

            Assert.Equal("log(sequence_i)", MemberContext.ForType <Product>().GetSolrMemberProduct(exp.Body));
        }
        public void Mul()
        {
            Expression <Func <Product, object> > exp = (Product p) => p.Popularity * 10;

            Assert.Equal("mul(popularity,10)", MemberContext.ForType <Product>().GetSolrMemberProduct(exp.Body));
        }