/// <inheritdoc/>
        public override string ToString()
        {
            var termOperator = "";
            var notOperator  = false;

            if (Operator == TermsOperator.Any || Operator == TermsOperator.NotAny)
            {
                termOperator = "any";

                if (Operator == TermsOperator.NotAny)
                {
                    notOperator = true;
                }

                if (Values.Count > 1 && !TypeHelper.IsPropertyNonStringEnumerable(TypeHelper.GetReturnType(Member)))
                {
                    return($"search.in({Field}, '{string.Join("|", Values)}', '|')");
                }
            }
            else if (Operator == TermsOperator.All || Operator == TermsOperator.NotAll)
            {
                termOperator = "all";

                if (Operator == TermsOperator.NotAll)
                {
                    notOperator = true;
                }
            }
            else
            {
                throw new KeyNotFoundException($"Term operator {Operator} not mapped!");
            }

            var filter = $"{Field}/{termOperator}(t: ";

            if (Values.Count == 1)
            {
                filter += $"t {(notOperator ? "ne " : "eq")} {ValueHelper.ConvertToSearchSafeValue(Values.First())}";
            }
            else
            {
                filter += $"{(notOperator ? "not " : "")}search.in(t, '{string.Join("|", Values)}', '|')";
            }

            return(filter + ")");
        }
Beispiel #2
0
        Expression VisitOrderBy(Expression source, Expression orderByExpression, bool ascending)
        {
            var lambda       = orderByExpression.GetLambda();
            var visited      = Visit(lambda.Body);
            var memberExpr   = visited as MemberExpression;
            var criteriaExpr = visited as CriteriaExpression;
            var orderBy      = "";

            if (memberExpr != null)
            {
                var fieldName = Mapping.GetFieldName(SourceType, memberExpr);

                if (!string.IsNullOrWhiteSpace(fieldName))
                {
                    orderBy = fieldName;
                }
            }
            else if (criteriaExpr != null)
            {
                var distanceCriteria = criteriaExpr.Criteria as DistanceCriteria;

                if (distanceCriteria != null)
                {
                    orderBy = $"geo.distance({distanceCriteria.Field}, geography'POINT("
                              + $"{ValueHelper.ConvertToSearchSafeValue(distanceCriteria.Value.Longitude)} "
                              + $"{ValueHelper.ConvertToSearchSafeValue(distanceCriteria.Value.Latitude)})')";
                }
            }

            if (!string.IsNullOrWhiteSpace(orderBy))
            {
                if (!ascending)
                {
                    orderBy += " desc";
                }

                searchRequest.AddOrderByField(orderBy);
            }

            return(Visit(source));
        }
Beispiel #3
0
 public override string ToString()
 {
     return($"geo.distance({Field}, geography'POINT({ValueHelper.ConvertToSearchSafeValue(Value.Longitude)} "
            + $"{ValueHelper.ConvertToSearchSafeValue(Value.Latitude)})') {CriteriaForComparison.ToString()}");
 }
 /// <inheritdoc/>
 public override string ToString()
 {
     return($"{Name} {ValueHelper.ConvertToSearchSafeValue(Value)}");
 }